OMG stupid typo

This commit is contained in:
Peter Cottle 2013-01-02 16:38:15 -08:00
parent de9d91773a
commit 2f57f4cfe3
11 changed files with 8247 additions and 7977 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,6 @@ var _ = require('underscore');
var Backbone = require('backbone');
var Constants = require('../util/constants');
var Views = require('../views');
var util = require('../util');
/**
@ -53,6 +52,7 @@ var init = function() {
eventBaton.stealBaton('zoomChange', function(level) {
if (level > Constants.VIEWPORT.maxZoom ||
level < Constants.VIEWPORT.minZoom) {
var Views = require('../views');
var view = new Views.ZoomAlertWindow();
}
});

View file

@ -1,10 +1,12 @@
var _ = require('underscore');
var Backbone = require('backbone');
var Q = require('q');
var GitEngine = require('../git').GitEngine;
var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
var GitVisuals = require('../visuals').GitVisuals;
var TreeCompare = require('../git/treeCompare').TreeCompare;
var EventBaton = require('../util/eventBaton').EventBaton;
var Collections = require('../models/collections');
var CommitCollection = Collections.CommitCollection;
@ -33,7 +35,7 @@ HeadlessGit.prototype.init = function() {
branches: this.branchCollection,
gitVisuals: gitVisuals,
animationFactory: animationFactory,
events: _.clone(Backbone.Events)
eventBaton: new EventBaton()
});
this.gitEngine.init();
};
@ -44,8 +46,7 @@ HeadlessGit.prototype.sendCommand = function(value) {
rawStr: commandStr
});
console.log('dispatching command "', commandStr, '"');
var done = function() {};
this.gitEngine.dispatch(commandObj, done);
this.gitEngine.dispatch(commandObj, Q.defer());
}, this);
};

View file

@ -19,7 +19,10 @@ function GitEngine(options) {
this.branchCollection = options.branches;
this.commitCollection = options.collection;
this.gitVisuals = options.gitVisuals;
this.events = options.events;
this.eventBaton = options.eventBaton;
this.eventBaton.stealBaton('processGitCommand', this.dispatch, this);
this.animationFactory = options.animationFactory ||
new AnimationFactoryModule.AnimationFactory();
@ -28,7 +31,6 @@ function GitEngine(options) {
this.commandOptions = {};
this.generalArgs = [];
this.events.on('processGitCommand', this.dispatch, this);
// backbone or something uses _.uniqueId, so we make our own here
this.uniqueId = (function() {
@ -1340,7 +1342,7 @@ GitEngine.prototype.filterError = function(err) {
}
};
GitEngine.prototype.dispatch = function(command, callback) {
GitEngine.prototype.dispatch = function(command, deferred) {
// current command, options, and args are stored in the gitEngine
// for easy reference during processing.
this.command = command;
@ -1349,8 +1351,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
// set up the animation queue
var whenDone = _.bind(function() {
command.set('status', 'finished');
callback();
command.finishWith(deferred);
}, this);
this.animationQueue = new AnimationQueue({
callback: whenDone
@ -1363,7 +1364,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
this.filterError(err);
// short circuit animation by just setting error and returning
command.set('error', err);
callback();
deferred.resolve();
return;
}

View file

@ -8,6 +8,7 @@ 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;
@ -26,10 +27,17 @@ 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(
'instantWaterfall',
new DisabledMap().getInstantCommands()
);
);*/
if (!options.defer) {
this.takeControl();
@ -37,8 +45,17 @@ function Sandbox(options) {
}
Sandbox.prototype.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);
Main.getEvents().on('processSandboxCommand', this.processSandboxCommand, this);
// we obviously take care of sandbox commands
Main.getEventBaton().stealBaton('processSandboxCommand', this.processSandboxCommand, this);
// and our git shim
// TODO HACKY
setTimeout(_.bind(function() {
this.gitShim.insertShim();
}, this), 1000);
};
Sandbox.prototype.commandSubmitted = function(value) {
@ -53,24 +70,23 @@ Sandbox.prototype.commandSubmitted = function(value) {
}, this);
};
Sandbox.prototype.processSandboxCommand = function(command, callback) {
Sandbox.prototype.processSandboxCommand = function(command, deferred) {
var commandMap = {
help: this.helpDialog
};
var method = commandMap[command.get('method')];
if (!method) { throw new Error('no method for that wut'); }
method.apply(this, [command, callback]);
method.apply(this, [command, deferred]);
};
Sandbox.prototype.helpDialog = function(command, callback) {
Sandbox.prototype.helpDialog = function(command, deferred) {
var helpDialog = new MultiView({
childViews: require('../dialogs/sandbox').helpDialog
});
helpDialog.getPromise().then(_.bind(function() {
// the view has been closed, lets go ahead and resolve our command
command.set('status', 'finished');
callback();
command.finishWith(deferred);
}, this))
.done();
};

View file

@ -1,4 +1,5 @@
var _ = require('underscore');
var Q = require('q');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone;
@ -79,9 +80,10 @@ var CommandBuffer = Backbone.Model.extend({
processCommand: function(command) {
command.set('status', 'processing');
var callback = _.bind(function() {
var deferred = Q.defer();
deferred.promise.then(_.bind(function() {
this.setTimeout();
}, this);
}, this));
var eventName = command.get('eventName');
if (!eventName) {
@ -89,7 +91,7 @@ var CommandBuffer = Backbone.Model.extend({
}
var Main = require('../app');
Main.getEvents().trigger(eventName, command, callback);
Main.getEventBaton().trigger(eventName, command, deferred);
},
clear: function() {

View file

@ -65,6 +65,11 @@ var Command = Backbone.Model.extend({
this.set('result', msg);
},
finishWith: function(deferred) {
this.set('status', 'finished');
deferred.resolve();
},
addWarning: function(msg) {
this.get('warnings').push(msg);
// change numWarnings so the change event fires. This is bizarre -- Backbone can't

View file

@ -19,30 +19,63 @@ EventBaton.prototype.stealBaton = function(name, func, context) {
this.eventMap[name] = listeners;
};
EventBaton.prototype.sliceOffArgs = function(num, args) {
var newArgs = [];
for (var i = num; i < args.length; i++) {
newArgs.push(args[i]);
}
return newArgs;
};
EventBaton.prototype.trigger = function(name) {
// arguments is weird and doesnt do slice right
var argsToApply = [];
for (var i = 1; i < arguments.length; i++) {
argsToApply.push(arguments[i]);
}
var argsToApply = this.sliceOffArgs(1, arguments);
var listeners = this.eventMap[name];
if (!listeners || !listeners.length) {
console.warn('no listeners for', name);
return;
}
// call the top most listener with context and such
var toCall = listeners.slice(-1)[0];
toCall.func.apply(toCall.context, argsToApply);
};
EventBaton.prototype.releaseBaton = function(name, func, context) {
if (!name) { throw new Error('need name'); }
// might be in the middle of the stack
EventBaton.prototype.getListenersThrow = function(name) {
var listeners = this.eventMap[name];
if (!listeners || !listeners.length) {
throw new Error('no one has that baton!' + name);
}
return listeners;
};
EventBaton.prototype.passBatonBack = function(name, func, context, args) {
// this method will call the listener BEFORE the name/func pair. this
// basically allows you to put in shims, where you steal batons but pass
// them back if they don't meet certain conditions
var listeners = this.getListenersThrow(name);
var indexBefore;
_.each(listeners, function(listenerObj, index) {
// skip the first
if (index === 0) { return; }
if (listenerObj.func === func && listenerObj.context === context) {
indexBefore = index - 1;
}
}, this);
if (indexBefore === undefined) {
throw new Error('you are the last baton holder! or i didnt find you');
}
var toCallObj = listeners[indexBefore];
toCallObj.func.apply(toCallObj.context, args);
};
EventBaton.prototype.releaseBaton = function(name, func, context) {
// might be in the middle of the stack, so we have to loop instead of
// just popping blindly
var listeners = this.getListenersThrow(name);
var newListeners = [];
var found = false;

View file

@ -4,7 +4,6 @@ var Backbone = require('backbone');
var GRAPHICS = require('../util/constants').GRAPHICS;
var GLOBAL = require('../util/constants').GLOBAL;
var Main = require('../app');
var Collections = require('../models/collections');
var CommitCollection = Collections.CommitCollection;
@ -37,6 +36,7 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = [];
var Main = require('../app');
Main.getEvents().on('refreshTree', this.refreshTree, this);
}
@ -618,6 +618,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
GitVisuals.prototype.canvasResize = _.debounce(function(width, height) {
// refresh when we are ready
if (GLOBAL.isAnimating) {
var Main = require('../app');
Main.getEventBaton().trigger('commandSubmitted', 'refresh');
} else {
this.refreshTree();

View file

@ -27,6 +27,7 @@ var Visualization = Backbone.View.extend({
var Main = require('../app');
this.events = options.events || Main.getEvents();
this.eventBaton = options.eventBaton || Main.getEventBaton();
this.commitCollection = new CommitCollection();
this.branchCollection = new BranchCollection();
@ -42,7 +43,7 @@ var Visualization = Backbone.View.extend({
collection: this.commitCollection,
branches: this.branchCollection,
gitVisuals: this.gitVisuals,
events: this.events
eventBaton: this.eventBaton
});
this.gitEngine.init();
this.gitVisuals.assignGitEngine(this.gitEngine);

View file

@ -10,9 +10,6 @@ Medium things:
Commands
========
[ ] transition to deferreds / promises for command callbacks
[ ] sip from buffer with post-command hooks. ideally the git engine
knows nothing about the level being played
Small things to implement:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -32,6 +29,10 @@ Big Bugs to fix:
Done things:
(I only started this on Dec 17th 2012 to get a better sense of what was done)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[x] sip from buffer with post-command hooks. ideally the git engine
knows nothing about the level being played
[x] fix tests
[x] transition to deferreds / promises for command callbacks
[x] awesome ability to have dialogs and such handle command processing and block
[x] figure out why multiview baton passing doesn't work...
[x] multiple things can process!!!