ok moved sandbox to a backbone view for inheritance

This commit is contained in:
Peter Cottle 2013-01-03 12:37:55 -08:00
parent 134cc9f748
commit 2e92e106d4
5 changed files with 356 additions and 299 deletions

View file

@ -4467,7 +4467,8 @@ exports.splitTextCommand = function(value, func, context) {
});
require.define("/src/js/level/sandbox.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var Backbone = require('backbone');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
var util = require('../util');
var Main = require('../app');
@ -4483,7 +4484,11 @@ var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
function Sandbox(options) {
var Sandbox = Backbone.View.extend({
// tag name here is purely vestigial. I made this a view
// simply to use inheritance and have a nice event system in place
tagName: 'div',
initialize: function(options) {
options = options || {};
this.mainVis = new Visualization({
@ -4495,11 +4500,11 @@ function Sandbox(options) {
this.commandCollection = Main.getCommandUI().commandCollection;
this.parseWaterfall = new ParseWaterfall();
/*
this.gitShim = new GitShim({
beforeCB: function() { console.log('before'); },
afterCB: function() { console.log('after'); }
});
});*/
/* DISBALED MAP example!!!
this.parseWaterfall.addFirst(
@ -4507,12 +4512,12 @@ function Sandbox(options) {
new DisabledMap().getInstantCommands()
);*/
if (!options.defer) {
if (!options.wait) {
this.takeControl();
}
}
},
Sandbox.prototype.takeControl = function() {
takeControl: function() {
// we will be handling commands that are submitted, mainly to add the sanadbox
// functionality (which is included by default in ParseWaterfall())
Main.getEventBaton().stealBaton('commandSubmitted', this.commandSubmitted, this);
@ -4521,12 +4526,14 @@ Sandbox.prototype.takeControl = function() {
// and our git shim
// TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf
if (this.gitShim) {
setTimeout(_.bind(function() {
this.gitShim.insertShim();
}, this), 1000);
};
}
},
Sandbox.prototype.commandSubmitted = function(value) {
commandSubmitted: function(value) {
// allow other things to see this command
Main.getEvents().trigger('commandSubmittedPassive', value);
@ -4536,9 +4543,9 @@ Sandbox.prototype.commandSubmitted = function(value) {
parseWaterfall: this.parseWaterfall
}));
}, this);
};
},
Sandbox.prototype.processSandboxCommand = function(command, deferred) {
processSandboxCommand: function(command, deferred) {
var commandMap = {
help: this.helpDialog
};
@ -4546,9 +4553,9 @@ Sandbox.prototype.processSandboxCommand = function(command, deferred) {
if (!method) { throw new Error('no method for that wut'); }
method.apply(this, [command, deferred]);
};
},
Sandbox.prototype.helpDialog = function(command, deferred) {
helpDialog: function(command, deferred) {
var helpDialog = new MultiView({
childViews: require('../dialogs/sandbox').helpDialog
});
@ -4557,11 +4564,11 @@ Sandbox.prototype.helpDialog = function(command, deferred) {
command.finishWith(deferred);
}, this))
.done();
};
}
});
exports.Sandbox = Sandbox;
});
require.define("/src/js/app/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
@ -14327,21 +14334,6 @@ function GitShim(options) {
};
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();
}
@ -14350,17 +14342,18 @@ GitShim.prototype.insertShim = function() {
};
GitShim.prototype.processGitCommand = function(command, deferred) {
console.log('in before');
this.beforeCB(command);
// 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() {
newDeferred.promise
.then(_.bind(function() {
// give this method the original defer so it can resolve it
this.afterGitCommandProcessed(command, deferred);
}, this));
}, this))
.done();
// 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
@ -14372,7 +14365,9 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
}, this);
var beforeDefer = Q.defer();
beforeDefer.promise.then(passBaton);
beforeDefer.promise
.then(passBaton)
.done();
// if we didnt receive a defer handler in the options, this just
// resolves immediately
@ -14381,7 +14376,18 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
this.afterCB(command);
// again we can't just resolve this deferred right away... our shim owner might
// want to insert some promise functionality before that happens. so again
// we make a defer
var afterDefer = Q.defer();
afterDefer.promise
.then(function() {
deferred.resolve();
})
.done();
this.afterDeferHandler(afterDefer);
};
exports.GitShim = GitShim;
@ -14426,16 +14432,6 @@ var MultiView = Backbone.View.extend({
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}];
this.deferred = options.deferred || Q.defer();
@ -15050,21 +15046,6 @@ function GitShim(options) {
};
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();
}
@ -15073,17 +15054,18 @@ GitShim.prototype.insertShim = function() {
};
GitShim.prototype.processGitCommand = function(command, deferred) {
console.log('in before');
this.beforeCB(command);
// 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() {
newDeferred.promise
.then(_.bind(function() {
// give this method the original defer so it can resolve it
this.afterGitCommandProcessed(command, deferred);
}, this));
}, this))
.done();
// 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
@ -15095,7 +15077,9 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
}, this);
var beforeDefer = Q.defer();
beforeDefer.promise.then(passBaton);
beforeDefer.promise
.then(passBaton)
.done();
// if we didnt receive a defer handler in the options, this just
// resolves immediately
@ -15104,7 +15088,18 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
this.afterCB(command);
// again we can't just resolve this deferred right away... our shim owner might
// want to insert some promise functionality before that happens. so again
// we make a defer
var afterDefer = Q.defer();
afterDefer.promise
.then(function() {
deferred.resolve();
})
.done();
this.afterDeferHandler(afterDefer);
};
exports.GitShim = GitShim;
@ -17014,6 +17009,42 @@ exports.DisabledMap = DisabledMap;
});
require("/src/js/level/disabledMap.js");
require.define("/src/js/level/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var Backbone = require('backbone');
var Q = require('q');
var util = require('../util');
var Main = require('../app');
var Visualization = require('../visuals/visualization').Visualization;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
var Command = require('../models/commandModel').Command;
var GitShim = require('../git/gitShim').GitShim;
var ModalTerminal = require('../views').ModalTerminal;
var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
/*
this.beforeDeferHandler = function(deferred) {
var view = new MultiView({
});
view.getPromise()
.then(function() {
return Q.delay(700);
})
.then(function() {
deferred.resolve();
})
.done();
};*/
});
require("/src/js/level/index.js");
require.define("/src/js/level/parseWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var GitCommands = require('../git/commands');
@ -17114,7 +17145,8 @@ exports.ParseWaterfall = ParseWaterfall;
require("/src/js/level/parseWaterfall.js");
require.define("/src/js/level/sandbox.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
var Backbone = require('backbone');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
var util = require('../util');
var Main = require('../app');
@ -17130,7 +17162,11 @@ var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
function Sandbox(options) {
var Sandbox = Backbone.View.extend({
// tag name here is purely vestigial. I made this a view
// simply to use inheritance and have a nice event system in place
tagName: 'div',
initialize: function(options) {
options = options || {};
this.mainVis = new Visualization({
@ -17142,11 +17178,11 @@ function Sandbox(options) {
this.commandCollection = Main.getCommandUI().commandCollection;
this.parseWaterfall = new ParseWaterfall();
/*
this.gitShim = new GitShim({
beforeCB: function() { console.log('before'); },
afterCB: function() { console.log('after'); }
});
});*/
/* DISBALED MAP example!!!
this.parseWaterfall.addFirst(
@ -17154,12 +17190,12 @@ function Sandbox(options) {
new DisabledMap().getInstantCommands()
);*/
if (!options.defer) {
if (!options.wait) {
this.takeControl();
}
}
},
Sandbox.prototype.takeControl = function() {
takeControl: function() {
// we will be handling commands that are submitted, mainly to add the sanadbox
// functionality (which is included by default in ParseWaterfall())
Main.getEventBaton().stealBaton('commandSubmitted', this.commandSubmitted, this);
@ -17168,12 +17204,14 @@ Sandbox.prototype.takeControl = function() {
// and our git shim
// TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf
if (this.gitShim) {
setTimeout(_.bind(function() {
this.gitShim.insertShim();
}, this), 1000);
};
}
},
Sandbox.prototype.commandSubmitted = function(value) {
commandSubmitted: function(value) {
// allow other things to see this command
Main.getEvents().trigger('commandSubmittedPassive', value);
@ -17183,9 +17221,9 @@ Sandbox.prototype.commandSubmitted = function(value) {
parseWaterfall: this.parseWaterfall
}));
}, this);
};
},
Sandbox.prototype.processSandboxCommand = function(command, deferred) {
processSandboxCommand: function(command, deferred) {
var commandMap = {
help: this.helpDialog
};
@ -17193,9 +17231,9 @@ Sandbox.prototype.processSandboxCommand = function(command, deferred) {
if (!method) { throw new Error('no method for that wut'); }
method.apply(this, [command, deferred]);
};
},
Sandbox.prototype.helpDialog = function(command, deferred) {
helpDialog: function(command, deferred) {
var helpDialog = new MultiView({
childViews: require('../dialogs/sandbox').helpDialog
});
@ -17204,11 +17242,11 @@ Sandbox.prototype.helpDialog = function(command, deferred) {
command.finishWith(deferred);
}, this))
.done();
};
}
});
exports.Sandbox = Sandbox;
});
require("/src/js/level/sandbox.js");
@ -18685,16 +18723,6 @@ var MultiView = Backbone.View.extend({
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}];
this.deferred = options.deferred || Q.defer();

View file

@ -20,20 +20,6 @@ function GitShim(options) {
};
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();
}
@ -42,17 +28,18 @@ GitShim.prototype.insertShim = function() {
};
GitShim.prototype.processGitCommand = function(command, deferred) {
console.log('in before');
this.beforeCB(command);
// 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() {
newDeferred.promise
.then(_.bind(function() {
// give this method the original defer so it can resolve it
this.afterGitCommandProcessed(command, deferred);
}, this));
}, this))
.done();
// 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
@ -64,7 +51,9 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
}, this);
var beforeDefer = Q.defer();
beforeDefer.promise.then(passBaton);
beforeDefer.promise
.then(passBaton)
.done();
// if we didnt receive a defer handler in the options, this just
// resolves immediately
@ -73,7 +62,18 @@ GitShim.prototype.processGitCommand = function(command, deferred) {
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) {
this.afterCB(command);
// again we can't just resolve this deferred right away... our shim owner might
// want to insert some promise functionality before that happens. so again
// we make a defer
var afterDefer = Q.defer();
afterDefer.promise
.then(function() {
deferred.resolve();
})
.done();
this.afterDeferHandler(afterDefer);
};
exports.GitShim = GitShim;

View file

@ -0,0 +1,32 @@
var _ = require('underscore');
var Backbone = require('backbone');
var Q = require('q');
var util = require('../util');
var Main = require('../app');
var Visualization = require('../visuals/visualization').Visualization;
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
var DisabledMap = require('../level/disabledMap').DisabledMap;
var Command = require('../models/commandModel').Command;
var GitShim = require('../git/gitShim').GitShim;
var ModalTerminal = require('../views').ModalTerminal;
var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
/*
this.beforeDeferHandler = function(deferred) {
var view = new MultiView({
});
view.getPromise()
.then(function() {
return Q.delay(700);
})
.then(function() {
deferred.resolve();
})
.done();
};*/

View file

@ -1,5 +1,6 @@
var _ = require('underscore');
var Backbone = require('backbone');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
var util = require('../util');
var Main = require('../app');
@ -15,7 +16,11 @@ var ModalAlert = require('../views').ModalAlert;
var MultiView = require('../views/multiView').MultiView;
function Sandbox(options) {
var Sandbox = Backbone.View.extend({
// tag name here is purely vestigial. I made this a view
// simply to use inheritance and have a nice event system in place
tagName: 'div',
initialize: function(options) {
options = options || {};
this.mainVis = new Visualization({
@ -27,11 +32,11 @@ function Sandbox(options) {
this.commandCollection = Main.getCommandUI().commandCollection;
this.parseWaterfall = new ParseWaterfall();
/*
this.gitShim = new GitShim({
beforeCB: function() { console.log('before'); },
afterCB: function() { console.log('after'); }
});
});*/
/* DISBALED MAP example!!!
this.parseWaterfall.addFirst(
@ -39,12 +44,12 @@ function Sandbox(options) {
new DisabledMap().getInstantCommands()
);*/
if (!options.defer) {
if (!options.wait) {
this.takeControl();
}
}
},
Sandbox.prototype.takeControl = function() {
takeControl: function() {
// we will be handling commands that are submitted, mainly to add the sanadbox
// functionality (which is included by default in ParseWaterfall())
Main.getEventBaton().stealBaton('commandSubmitted', this.commandSubmitted, this);
@ -53,12 +58,14 @@ Sandbox.prototype.takeControl = function() {
// and our git shim
// TODO HACKY needs to be AFTER PAPER INITIALIZE dropped down from visualization wtf
if (this.gitShim) {
setTimeout(_.bind(function() {
this.gitShim.insertShim();
}, this), 1000);
};
}
},
Sandbox.prototype.commandSubmitted = function(value) {
commandSubmitted: function(value) {
// allow other things to see this command
Main.getEvents().trigger('commandSubmittedPassive', value);
@ -68,9 +75,9 @@ Sandbox.prototype.commandSubmitted = function(value) {
parseWaterfall: this.parseWaterfall
}));
}, this);
};
},
Sandbox.prototype.processSandboxCommand = function(command, deferred) {
processSandboxCommand: function(command, deferred) {
var commandMap = {
help: this.helpDialog
};
@ -78,9 +85,9 @@ Sandbox.prototype.processSandboxCommand = function(command, deferred) {
if (!method) { throw new Error('no method for that wut'); }
method.apply(this, [command, deferred]);
};
},
Sandbox.prototype.helpDialog = function(command, deferred) {
helpDialog: function(command, deferred) {
var helpDialog = new MultiView({
childViews: require('../dialogs/sandbox').helpDialog
});
@ -89,7 +96,7 @@ Sandbox.prototype.helpDialog = function(command, deferred) {
command.finishWith(deferred);
}, this))
.done();
};
}
});
exports.Sandbox = Sandbox;

View file

@ -35,16 +35,6 @@ var MultiView = Backbone.View.extend({
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}, {
type: 'ModalAlert',
options: {
markdown: 'Im second'
}
}];
this.deferred = options.deferred || Q.defer();