diff --git a/build/bundle.js b/build/bundle.js index 57bb35c2..363226d2 100644 --- a/build/bundle.js +++ b/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)); - // punt to the previous listener - this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]); + // 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)); - // punt to the previous listener - this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]); + // 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() { diff --git a/src/js/git/gitShim.js b/src/js/git/gitShim.js index 5f9512b0..5d5b9cac 100644 --- a/src/js/git/gitShim.js +++ b/src/js/git/gitShim.js @@ -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)); - // punt to the previous listener - this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]); + // 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(); }; diff --git a/src/js/level/index.js b/src/js/level/index.js new file mode 100644 index 00000000..e69de29b diff --git a/src/js/views/multiView.js b/src/js/views/multiView.js index 97670b98..13209822 100644 --- a/src/js/views/multiView.js +++ b/src/js/views/multiView.js @@ -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() { diff --git a/todo.txt b/todo.txt index d12fedd5..3c31d4fe 100644 --- a/todo.txt +++ b/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