mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
awesome before and after deferreds working
This commit is contained in:
parent
4e6e82e698
commit
134cc9f748
5 changed files with 159 additions and 24 deletions
114
build/bundle.js
114
build/bundle.js
|
@ -14309,38 +14309,78 @@ require.define("/src/js/git/gitShim.js",function(require,module,exports,__dirnam
|
|||
var Q = require('q');
|
||||
|
||||
var Main = require('../app');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
function GitShim(options) {
|
||||
options = options || {};
|
||||
|
||||
// these variables are just functions called before / after for
|
||||
// simple things (like incrementing a counter)
|
||||
this.beforeCB = options.beforeCB || function() {};
|
||||
this.afterCB = options.afterCB || function() {};
|
||||
|
||||
// these guys handle an optional async process before the git
|
||||
// command executes or afterwards. If there is none,
|
||||
// it just resolves the deferred immediately
|
||||
var resolveImmediately = function(deferred) {
|
||||
deferred.resolve();
|
||||
};
|
||||
this.beforeDeferHandler = options.beforeDeferHandler || resolveImmediately;
|
||||
this.afterDeferHandler = options.afterDeferHandler || resolveImmediately;
|
||||
|
||||
this.beforeDeferHandler = function(deferred) {
|
||||
var view = new MultiView({
|
||||
});
|
||||
view.getPromise()
|
||||
.then(function() {
|
||||
return Q.delay(700);
|
||||
})
|
||||
.then(function() {
|
||||
console.log('WUTTTTTTT');
|
||||
deferred.resolve();
|
||||
})
|
||||
.done();
|
||||
};
|
||||
|
||||
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||
}
|
||||
|
||||
GitShim.prototype.insertShim = function() {
|
||||
console.log('stealing baton');
|
||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||
console.log(this.eventBaton);
|
||||
};
|
||||
|
||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||
console.log('in before');
|
||||
this.beforeCB();
|
||||
this.beforeCB(command);
|
||||
|
||||
// ok we make a NEW deferred and pass it back
|
||||
// ok we make a NEW deferred that will, upon resolution,
|
||||
// call our afterGitCommandProcessed. This inserts the 'after' shim
|
||||
// functionality. we give this new deferred to the eventBaton handler
|
||||
var newDeferred = Q.defer();
|
||||
newDeferred.promise.then(_.bind(function() {
|
||||
// give this method the original defer so it can resolve it
|
||||
this.afterGitCommandProcessed(command, deferred);
|
||||
}, this));
|
||||
|
||||
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||
// a modal or something. in order to do this, we need to defer the passing
|
||||
// of the event baton backwards, and either resolve that promise immediately or
|
||||
// give it to our shim owner.
|
||||
var passBaton = _.bind(function() {
|
||||
// punt to the previous listener
|
||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
||||
}, this);
|
||||
|
||||
var beforeDefer = Q.defer();
|
||||
beforeDefer.promise.then(passBaton);
|
||||
|
||||
// if we didnt receive a defer handler in the options, this just
|
||||
// resolves immediately
|
||||
this.beforeDeferHandler(beforeDefer);
|
||||
};
|
||||
|
||||
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||
this.afterCB();
|
||||
this.afterCB(command);
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
|
@ -14397,7 +14437,7 @@ var MultiView = Backbone.View.extend({
|
|||
markdown: 'Im second'
|
||||
}
|
||||
}];
|
||||
this.deferred = Q.defer();
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
|
||||
this.childViews = [];
|
||||
this.currentIndex = 0;
|
||||
|
@ -14423,6 +14463,11 @@ var MultiView = Backbone.View.extend({
|
|||
|
||||
onWindowFocus: function() {
|
||||
// nothing here for now...
|
||||
// TODO -- add a cool glow effect?
|
||||
},
|
||||
|
||||
getAnimationTime: function() {
|
||||
return 700;
|
||||
},
|
||||
|
||||
getPromise: function() {
|
||||
|
@ -14987,38 +15032,78 @@ require.define("/src/js/git/gitShim.js",function(require,module,exports,__dirnam
|
|||
var Q = require('q');
|
||||
|
||||
var Main = require('../app');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
function GitShim(options) {
|
||||
options = options || {};
|
||||
|
||||
// these variables are just functions called before / after for
|
||||
// simple things (like incrementing a counter)
|
||||
this.beforeCB = options.beforeCB || function() {};
|
||||
this.afterCB = options.afterCB || function() {};
|
||||
|
||||
// these guys handle an optional async process before the git
|
||||
// command executes or afterwards. If there is none,
|
||||
// it just resolves the deferred immediately
|
||||
var resolveImmediately = function(deferred) {
|
||||
deferred.resolve();
|
||||
};
|
||||
this.beforeDeferHandler = options.beforeDeferHandler || resolveImmediately;
|
||||
this.afterDeferHandler = options.afterDeferHandler || resolveImmediately;
|
||||
|
||||
this.beforeDeferHandler = function(deferred) {
|
||||
var view = new MultiView({
|
||||
});
|
||||
view.getPromise()
|
||||
.then(function() {
|
||||
return Q.delay(700);
|
||||
})
|
||||
.then(function() {
|
||||
console.log('WUTTTTTTT');
|
||||
deferred.resolve();
|
||||
})
|
||||
.done();
|
||||
};
|
||||
|
||||
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||
}
|
||||
|
||||
GitShim.prototype.insertShim = function() {
|
||||
console.log('stealing baton');
|
||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||
console.log(this.eventBaton);
|
||||
};
|
||||
|
||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||
console.log('in before');
|
||||
this.beforeCB();
|
||||
this.beforeCB(command);
|
||||
|
||||
// ok we make a NEW deferred and pass it back
|
||||
// ok we make a NEW deferred that will, upon resolution,
|
||||
// call our afterGitCommandProcessed. This inserts the 'after' shim
|
||||
// functionality. we give this new deferred to the eventBaton handler
|
||||
var newDeferred = Q.defer();
|
||||
newDeferred.promise.then(_.bind(function() {
|
||||
// give this method the original defer so it can resolve it
|
||||
this.afterGitCommandProcessed(command, deferred);
|
||||
}, this));
|
||||
|
||||
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||
// a modal or something. in order to do this, we need to defer the passing
|
||||
// of the event baton backwards, and either resolve that promise immediately or
|
||||
// give it to our shim owner.
|
||||
var passBaton = _.bind(function() {
|
||||
// punt to the previous listener
|
||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
||||
}, this);
|
||||
|
||||
var beforeDefer = Q.defer();
|
||||
beforeDefer.promise.then(passBaton);
|
||||
|
||||
// if we didnt receive a defer handler in the options, this just
|
||||
// resolves immediately
|
||||
this.beforeDeferHandler(beforeDefer);
|
||||
};
|
||||
|
||||
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||
this.afterCB();
|
||||
this.afterCB(command);
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
|
@ -18611,7 +18696,7 @@ var MultiView = Backbone.View.extend({
|
|||
markdown: 'Im second'
|
||||
}
|
||||
}];
|
||||
this.deferred = Q.defer();
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
|
||||
this.childViews = [];
|
||||
this.currentIndex = 0;
|
||||
|
@ -18637,6 +18722,11 @@ var MultiView = Backbone.View.extend({
|
|||
|
||||
onWindowFocus: function() {
|
||||
// nothing here for now...
|
||||
// TODO -- add a cool glow effect?
|
||||
},
|
||||
|
||||
getAnimationTime: function() {
|
||||
return 700;
|
||||
},
|
||||
|
||||
getPromise: function() {
|
||||
|
|
|
@ -2,38 +2,77 @@ var _ = require('underscore');
|
|||
var Q = require('q');
|
||||
|
||||
var Main = require('../app');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
function GitShim(options) {
|
||||
options = options || {};
|
||||
|
||||
// these variables are just functions called before / after for
|
||||
// simple things (like incrementing a counter)
|
||||
this.beforeCB = options.beforeCB || function() {};
|
||||
this.afterCB = options.afterCB || function() {};
|
||||
|
||||
// these guys handle an optional async process before the git
|
||||
// command executes or afterwards. If there is none,
|
||||
// it just resolves the deferred immediately
|
||||
var resolveImmediately = function(deferred) {
|
||||
deferred.resolve();
|
||||
};
|
||||
this.beforeDeferHandler = options.beforeDeferHandler || resolveImmediately;
|
||||
this.afterDeferHandler = options.afterDeferHandler || resolveImmediately;
|
||||
|
||||
this.beforeDeferHandler = function(deferred) {
|
||||
var view = new MultiView({
|
||||
});
|
||||
view.getPromise()
|
||||
.then(function() {
|
||||
return Q.delay(700);
|
||||
})
|
||||
.then(function() {
|
||||
deferred.resolve();
|
||||
})
|
||||
.done();
|
||||
};
|
||||
|
||||
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||
}
|
||||
|
||||
GitShim.prototype.insertShim = function() {
|
||||
console.log('stealing baton');
|
||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||
console.log(this.eventBaton);
|
||||
};
|
||||
|
||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||
console.log('in before');
|
||||
this.beforeCB();
|
||||
this.beforeCB(command);
|
||||
|
||||
// ok we make a NEW deferred and pass it back
|
||||
// ok we make a NEW deferred that will, upon resolution,
|
||||
// call our afterGitCommandProcessed. This inserts the 'after' shim
|
||||
// functionality. we give this new deferred to the eventBaton handler
|
||||
var newDeferred = Q.defer();
|
||||
newDeferred.promise.then(_.bind(function() {
|
||||
// give this method the original defer so it can resolve it
|
||||
this.afterGitCommandProcessed(command, deferred);
|
||||
}, this));
|
||||
|
||||
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||
// a modal or something. in order to do this, we need to defer the passing
|
||||
// of the event baton backwards, and either resolve that promise immediately or
|
||||
// give it to our shim owner.
|
||||
var passBaton = _.bind(function() {
|
||||
// punt to the previous listener
|
||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
||||
}, this);
|
||||
|
||||
var beforeDefer = Q.defer();
|
||||
beforeDefer.promise.then(passBaton);
|
||||
|
||||
// if we didnt receive a defer handler in the options, this just
|
||||
// resolves immediately
|
||||
this.beforeDeferHandler(beforeDefer);
|
||||
};
|
||||
|
||||
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||
this.afterCB();
|
||||
this.afterCB(command);
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
|
|
0
src/js/level/index.js
Normal file
0
src/js/level/index.js
Normal file
|
@ -46,7 +46,7 @@ var MultiView = Backbone.View.extend({
|
|||
markdown: 'Im second'
|
||||
}
|
||||
}];
|
||||
this.deferred = Q.defer();
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
|
||||
this.childViews = [];
|
||||
this.currentIndex = 0;
|
||||
|
@ -72,6 +72,11 @@ var MultiView = Backbone.View.extend({
|
|||
|
||||
onWindowFocus: function() {
|
||||
// nothing here for now...
|
||||
// TODO -- add a cool glow effect?
|
||||
},
|
||||
|
||||
getAnimationTime: function() {
|
||||
return 700;
|
||||
},
|
||||
|
||||
getPromise: function() {
|
||||
|
|
1
todo.txt
1
todo.txt
|
@ -29,6 +29,7 @@ Big Bugs to fix:
|
|||
Done things:
|
||||
(I only started this on Dec 17th 2012 to get a better sense of what was done)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[x] awesome before and after shims with event baton stealing and passing back
|
||||
[x] sip from buffer with post-command hooks. ideally the git engine
|
||||
knows nothing about the level being played
|
||||
[x] fix tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue