diff --git a/build/bundle.js b/build/bundle.js index e0e1dfdf..57bb35c2 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -4520,7 +4520,7 @@ Sandbox.prototype.takeControl = function() { Main.getEventBaton().stealBaton('processSandboxCommand', this.processSandboxCommand, this); // and our git shim - // TODO HACKY + // TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf setTimeout(_.bind(function() { this.gitShim.insertShim(); }, this), 1000); @@ -17082,7 +17082,7 @@ Sandbox.prototype.takeControl = function() { Main.getEventBaton().stealBaton('processSandboxCommand', this.processSandboxCommand, this); // and our git shim - // TODO HACKY + // TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf setTimeout(_.bind(function() { this.gitShim.insertShim(); }, this), 1000); diff --git a/src/js/git/gitShim.js b/src/js/git/gitShim.js new file mode 100644 index 00000000..5f9512b0 --- /dev/null +++ b/src/js/git/gitShim.js @@ -0,0 +1,41 @@ +var _ = require('underscore'); +var Q = require('q'); + +var Main = require('../app'); + +function GitShim(options) { + options = options || {}; + this.beforeCB = options.beforeCB || function() {}; + this.afterCB = options.afterCB || function() {}; + + 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(); + + // ok we make a NEW deferred and pass it back + 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]); +}; + +GitShim.prototype.afterGitCommandProcessed = function(command, deferred) { + this.afterCB(); + deferred.resolve(); +}; + +exports.GitShim = GitShim; + diff --git a/src/js/level/sandbox.js b/src/js/level/sandbox.js index 6b92c74d..b3990959 100644 --- a/src/js/level/sandbox.js +++ b/src/js/level/sandbox.js @@ -52,7 +52,7 @@ Sandbox.prototype.takeControl = function() { Main.getEventBaton().stealBaton('processSandboxCommand', this.processSandboxCommand, this); // and our git shim - // TODO HACKY + // TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf setTimeout(_.bind(function() { this.gitShim.insertShim(); }, this), 1000);