mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 08:28: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
122
build/bundle.js
122
build/bundle.js
|
@ -14309,38 +14309,78 @@ require.define("/src/js/git/gitShim.js",function(require,module,exports,__dirnam
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
|
|
||||||
var Main = require('../app');
|
var Main = require('../app');
|
||||||
|
var MultiView = require('../views/multiView').MultiView;
|
||||||
|
|
||||||
function GitShim(options) {
|
function GitShim(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
// these variables are just functions called before / after for
|
||||||
|
// simple things (like incrementing a counter)
|
||||||
this.beforeCB = options.beforeCB || function() {};
|
this.beforeCB = options.beforeCB || function() {};
|
||||||
this.afterCB = options.afterCB || 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();
|
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||||
}
|
}
|
||||||
|
|
||||||
GitShim.prototype.insertShim = function() {
|
GitShim.prototype.insertShim = function() {
|
||||||
console.log('stealing baton');
|
|
||||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||||
console.log(this.eventBaton);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||||
console.log('in before');
|
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();
|
var newDeferred = Q.defer();
|
||||||
newDeferred.promise.then(_.bind(function() {
|
newDeferred.promise.then(_.bind(function() {
|
||||||
// give this method the original defer so it can resolve it
|
// give this method the original defer so it can resolve it
|
||||||
this.afterGitCommandProcessed(command, deferred);
|
this.afterGitCommandProcessed(command, deferred);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
// punt to the previous listener
|
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
// 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) {
|
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||||
this.afterCB();
|
this.afterCB(command);
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14397,7 +14437,7 @@ var MultiView = Backbone.View.extend({
|
||||||
markdown: 'Im second'
|
markdown: 'Im second'
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
this.deferred = Q.defer();
|
this.deferred = options.deferred || Q.defer();
|
||||||
|
|
||||||
this.childViews = [];
|
this.childViews = [];
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
|
@ -14423,6 +14463,11 @@ var MultiView = Backbone.View.extend({
|
||||||
|
|
||||||
onWindowFocus: function() {
|
onWindowFocus: function() {
|
||||||
// nothing here for now...
|
// nothing here for now...
|
||||||
|
// TODO -- add a cool glow effect?
|
||||||
|
},
|
||||||
|
|
||||||
|
getAnimationTime: function() {
|
||||||
|
return 700;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPromise: function() {
|
getPromise: function() {
|
||||||
|
@ -14987,38 +15032,78 @@ require.define("/src/js/git/gitShim.js",function(require,module,exports,__dirnam
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
|
|
||||||
var Main = require('../app');
|
var Main = require('../app');
|
||||||
|
var MultiView = require('../views/multiView').MultiView;
|
||||||
|
|
||||||
function GitShim(options) {
|
function GitShim(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
// these variables are just functions called before / after for
|
||||||
|
// simple things (like incrementing a counter)
|
||||||
this.beforeCB = options.beforeCB || function() {};
|
this.beforeCB = options.beforeCB || function() {};
|
||||||
this.afterCB = options.afterCB || 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();
|
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||||
}
|
}
|
||||||
|
|
||||||
GitShim.prototype.insertShim = function() {
|
GitShim.prototype.insertShim = function() {
|
||||||
console.log('stealing baton');
|
|
||||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||||
console.log(this.eventBaton);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||||
console.log('in before');
|
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();
|
var newDeferred = Q.defer();
|
||||||
newDeferred.promise.then(_.bind(function() {
|
newDeferred.promise.then(_.bind(function() {
|
||||||
// give this method the original defer so it can resolve it
|
// give this method the original defer so it can resolve it
|
||||||
this.afterGitCommandProcessed(command, deferred);
|
this.afterGitCommandProcessed(command, deferred);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
// punt to the previous listener
|
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
// 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) {
|
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||||
this.afterCB();
|
this.afterCB(command);
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18611,7 +18696,7 @@ var MultiView = Backbone.View.extend({
|
||||||
markdown: 'Im second'
|
markdown: 'Im second'
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
this.deferred = Q.defer();
|
this.deferred = options.deferred || Q.defer();
|
||||||
|
|
||||||
this.childViews = [];
|
this.childViews = [];
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
|
@ -18637,6 +18722,11 @@ var MultiView = Backbone.View.extend({
|
||||||
|
|
||||||
onWindowFocus: function() {
|
onWindowFocus: function() {
|
||||||
// nothing here for now...
|
// nothing here for now...
|
||||||
|
// TODO -- add a cool glow effect?
|
||||||
|
},
|
||||||
|
|
||||||
|
getAnimationTime: function() {
|
||||||
|
return 700;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPromise: function() {
|
getPromise: function() {
|
||||||
|
|
|
@ -2,38 +2,77 @@ var _ = require('underscore');
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
|
|
||||||
var Main = require('../app');
|
var Main = require('../app');
|
||||||
|
var MultiView = require('../views/multiView').MultiView;
|
||||||
|
|
||||||
function GitShim(options) {
|
function GitShim(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
// these variables are just functions called before / after for
|
||||||
|
// simple things (like incrementing a counter)
|
||||||
this.beforeCB = options.beforeCB || function() {};
|
this.beforeCB = options.beforeCB || function() {};
|
||||||
this.afterCB = options.afterCB || 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();
|
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||||
}
|
}
|
||||||
|
|
||||||
GitShim.prototype.insertShim = function() {
|
GitShim.prototype.insertShim = function() {
|
||||||
console.log('stealing baton');
|
|
||||||
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this);
|
||||||
console.log(this.eventBaton);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GitShim.prototype.processGitCommand = function(command, deferred) {
|
GitShim.prototype.processGitCommand = function(command, deferred) {
|
||||||
console.log('in before');
|
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();
|
var newDeferred = Q.defer();
|
||||||
newDeferred.promise.then(_.bind(function() {
|
newDeferred.promise.then(_.bind(function() {
|
||||||
// give this method the original defer so it can resolve it
|
// give this method the original defer so it can resolve it
|
||||||
this.afterGitCommandProcessed(command, deferred);
|
this.afterGitCommandProcessed(command, deferred);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
// punt to the previous listener
|
// now our shim owner might want to launch some kind of deferred beforehand, like
|
||||||
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]);
|
// 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) {
|
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
|
||||||
this.afterCB();
|
this.afterCB(command);
|
||||||
deferred.resolve();
|
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'
|
markdown: 'Im second'
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
this.deferred = Q.defer();
|
this.deferred = options.deferred || Q.defer();
|
||||||
|
|
||||||
this.childViews = [];
|
this.childViews = [];
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
|
@ -72,6 +72,11 @@ var MultiView = Backbone.View.extend({
|
||||||
|
|
||||||
onWindowFocus: function() {
|
onWindowFocus: function() {
|
||||||
// nothing here for now...
|
// nothing here for now...
|
||||||
|
// TODO -- add a cool glow effect?
|
||||||
|
},
|
||||||
|
|
||||||
|
getAnimationTime: function() {
|
||||||
|
return 700;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPromise: function() {
|
getPromise: function() {
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -29,6 +29,7 @@ Big Bugs to fix:
|
||||||
Done things:
|
Done things:
|
||||||
(I only started this on Dec 17th 2012 to get a better sense of what was done)
|
(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
|
[x] sip from buffer with post-command hooks. ideally the git engine
|
||||||
knows nothing about the level being played
|
knows nothing about the level being played
|
||||||
[x] fix tests
|
[x] fix tests
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue