mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 23:48:34 +02:00
OMG stupid typo
This commit is contained in:
parent
de9d91773a
commit
2f57f4cfe3
11 changed files with 8247 additions and 7977 deletions
16099
build/bundle.js
16099
build/bundle.js
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,6 @@ var _ = require('underscore');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
|
|
||||||
var Constants = require('../util/constants');
|
var Constants = require('../util/constants');
|
||||||
var Views = require('../views');
|
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,6 +52,7 @@ var init = function() {
|
||||||
eventBaton.stealBaton('zoomChange', function(level) {
|
eventBaton.stealBaton('zoomChange', function(level) {
|
||||||
if (level > Constants.VIEWPORT.maxZoom ||
|
if (level > Constants.VIEWPORT.maxZoom ||
|
||||||
level < Constants.VIEWPORT.minZoom) {
|
level < Constants.VIEWPORT.minZoom) {
|
||||||
|
var Views = require('../views');
|
||||||
var view = new Views.ZoomAlertWindow();
|
var view = new Views.ZoomAlertWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
|
var Q = require('q');
|
||||||
|
|
||||||
var GitEngine = require('../git').GitEngine;
|
var GitEngine = require('../git').GitEngine;
|
||||||
var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
|
var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
|
||||||
var GitVisuals = require('../visuals').GitVisuals;
|
var GitVisuals = require('../visuals').GitVisuals;
|
||||||
var TreeCompare = require('../git/treeCompare').TreeCompare;
|
var TreeCompare = require('../git/treeCompare').TreeCompare;
|
||||||
|
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||||
|
|
||||||
var Collections = require('../models/collections');
|
var Collections = require('../models/collections');
|
||||||
var CommitCollection = Collections.CommitCollection;
|
var CommitCollection = Collections.CommitCollection;
|
||||||
|
@ -33,7 +35,7 @@ HeadlessGit.prototype.init = function() {
|
||||||
branches: this.branchCollection,
|
branches: this.branchCollection,
|
||||||
gitVisuals: gitVisuals,
|
gitVisuals: gitVisuals,
|
||||||
animationFactory: animationFactory,
|
animationFactory: animationFactory,
|
||||||
events: _.clone(Backbone.Events)
|
eventBaton: new EventBaton()
|
||||||
});
|
});
|
||||||
this.gitEngine.init();
|
this.gitEngine.init();
|
||||||
};
|
};
|
||||||
|
@ -44,8 +46,7 @@ HeadlessGit.prototype.sendCommand = function(value) {
|
||||||
rawStr: commandStr
|
rawStr: commandStr
|
||||||
});
|
});
|
||||||
console.log('dispatching command "', commandStr, '"');
|
console.log('dispatching command "', commandStr, '"');
|
||||||
var done = function() {};
|
this.gitEngine.dispatch(commandObj, Q.defer());
|
||||||
this.gitEngine.dispatch(commandObj, done);
|
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ function GitEngine(options) {
|
||||||
this.branchCollection = options.branches;
|
this.branchCollection = options.branches;
|
||||||
this.commitCollection = options.collection;
|
this.commitCollection = options.collection;
|
||||||
this.gitVisuals = options.gitVisuals;
|
this.gitVisuals = options.gitVisuals;
|
||||||
this.events = options.events;
|
|
||||||
|
this.eventBaton = options.eventBaton;
|
||||||
|
this.eventBaton.stealBaton('processGitCommand', this.dispatch, this);
|
||||||
|
|
||||||
this.animationFactory = options.animationFactory ||
|
this.animationFactory = options.animationFactory ||
|
||||||
new AnimationFactoryModule.AnimationFactory();
|
new AnimationFactoryModule.AnimationFactory();
|
||||||
|
|
||||||
|
@ -28,7 +31,6 @@ function GitEngine(options) {
|
||||||
this.commandOptions = {};
|
this.commandOptions = {};
|
||||||
this.generalArgs = [];
|
this.generalArgs = [];
|
||||||
|
|
||||||
this.events.on('processGitCommand', this.dispatch, this);
|
|
||||||
|
|
||||||
// backbone or something uses _.uniqueId, so we make our own here
|
// backbone or something uses _.uniqueId, so we make our own here
|
||||||
this.uniqueId = (function() {
|
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
|
// current command, options, and args are stored in the gitEngine
|
||||||
// for easy reference during processing.
|
// for easy reference during processing.
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
@ -1349,8 +1351,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
|
||||||
|
|
||||||
// set up the animation queue
|
// set up the animation queue
|
||||||
var whenDone = _.bind(function() {
|
var whenDone = _.bind(function() {
|
||||||
command.set('status', 'finished');
|
command.finishWith(deferred);
|
||||||
callback();
|
|
||||||
}, this);
|
}, this);
|
||||||
this.animationQueue = new AnimationQueue({
|
this.animationQueue = new AnimationQueue({
|
||||||
callback: whenDone
|
callback: whenDone
|
||||||
|
@ -1363,7 +1364,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
|
||||||
this.filterError(err);
|
this.filterError(err);
|
||||||
// short circuit animation by just setting error and returning
|
// short circuit animation by just setting error and returning
|
||||||
command.set('error', err);
|
command.set('error', err);
|
||||||
callback();
|
deferred.resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ var Visualization = require('../visuals/visualization').Visualization;
|
||||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||||
var Command = require('../models/commandModel').Command;
|
var Command = require('../models/commandModel').Command;
|
||||||
|
var GitShim = require('../git/gitShim').GitShim;
|
||||||
|
|
||||||
var ModalTerminal = require('../views').ModalTerminal;
|
var ModalTerminal = require('../views').ModalTerminal;
|
||||||
var ModalAlert = require('../views').ModalAlert;
|
var ModalAlert = require('../views').ModalAlert;
|
||||||
|
@ -26,10 +27,17 @@ function Sandbox(options) {
|
||||||
this.commandCollection = Main.getCommandUI().commandCollection;
|
this.commandCollection = Main.getCommandUI().commandCollection;
|
||||||
|
|
||||||
this.parseWaterfall = new ParseWaterfall();
|
this.parseWaterfall = new ParseWaterfall();
|
||||||
|
|
||||||
|
this.gitShim = new GitShim({
|
||||||
|
beforeCB: function() { console.log('before'); },
|
||||||
|
afterCB: function() { console.log('after'); }
|
||||||
|
});
|
||||||
|
|
||||||
|
/* DISBALED MAP example!!!
|
||||||
this.parseWaterfall.addFirst(
|
this.parseWaterfall.addFirst(
|
||||||
'instantWaterfall',
|
'instantWaterfall',
|
||||||
new DisabledMap().getInstantCommands()
|
new DisabledMap().getInstantCommands()
|
||||||
);
|
);*/
|
||||||
|
|
||||||
if (!options.defer) {
|
if (!options.defer) {
|
||||||
this.takeControl();
|
this.takeControl();
|
||||||
|
@ -37,8 +45,17 @@ function Sandbox(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Sandbox.prototype.takeControl = function() {
|
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.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) {
|
Sandbox.prototype.commandSubmitted = function(value) {
|
||||||
|
@ -53,24 +70,23 @@ Sandbox.prototype.commandSubmitted = function(value) {
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Sandbox.prototype.processSandboxCommand = function(command, callback) {
|
Sandbox.prototype.processSandboxCommand = function(command, deferred) {
|
||||||
var commandMap = {
|
var commandMap = {
|
||||||
help: this.helpDialog
|
help: this.helpDialog
|
||||||
};
|
};
|
||||||
var method = commandMap[command.get('method')];
|
var method = commandMap[command.get('method')];
|
||||||
if (!method) { throw new Error('no method for that wut'); }
|
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({
|
var helpDialog = new MultiView({
|
||||||
childViews: require('../dialogs/sandbox').helpDialog
|
childViews: require('../dialogs/sandbox').helpDialog
|
||||||
});
|
});
|
||||||
helpDialog.getPromise().then(_.bind(function() {
|
helpDialog.getPromise().then(_.bind(function() {
|
||||||
// the view has been closed, lets go ahead and resolve our command
|
// the view has been closed, lets go ahead and resolve our command
|
||||||
command.set('status', 'finished');
|
command.finishWith(deferred);
|
||||||
callback();
|
|
||||||
}, this))
|
}, this))
|
||||||
.done();
|
.done();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var Q = require('q');
|
||||||
// horrible hack to get localStorage Backbone plugin
|
// horrible hack to get localStorage Backbone plugin
|
||||||
var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone;
|
var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone;
|
||||||
|
|
||||||
|
@ -79,9 +80,10 @@ var CommandBuffer = Backbone.Model.extend({
|
||||||
processCommand: function(command) {
|
processCommand: function(command) {
|
||||||
command.set('status', 'processing');
|
command.set('status', 'processing');
|
||||||
|
|
||||||
var callback = _.bind(function() {
|
var deferred = Q.defer();
|
||||||
|
deferred.promise.then(_.bind(function() {
|
||||||
this.setTimeout();
|
this.setTimeout();
|
||||||
}, this);
|
}, this));
|
||||||
|
|
||||||
var eventName = command.get('eventName');
|
var eventName = command.get('eventName');
|
||||||
if (!eventName) {
|
if (!eventName) {
|
||||||
|
@ -89,7 +91,7 @@ var CommandBuffer = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
var Main = require('../app');
|
var Main = require('../app');
|
||||||
Main.getEvents().trigger(eventName, command, callback);
|
Main.getEventBaton().trigger(eventName, command, deferred);
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function() {
|
clear: function() {
|
||||||
|
|
|
@ -65,6 +65,11 @@ var Command = Backbone.Model.extend({
|
||||||
this.set('result', msg);
|
this.set('result', msg);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
finishWith: function(deferred) {
|
||||||
|
this.set('status', 'finished');
|
||||||
|
deferred.resolve();
|
||||||
|
},
|
||||||
|
|
||||||
addWarning: function(msg) {
|
addWarning: function(msg) {
|
||||||
this.get('warnings').push(msg);
|
this.get('warnings').push(msg);
|
||||||
// change numWarnings so the change event fires. This is bizarre -- Backbone can't
|
// change numWarnings so the change event fires. This is bizarre -- Backbone can't
|
||||||
|
|
|
@ -19,30 +19,63 @@ EventBaton.prototype.stealBaton = function(name, func, context) {
|
||||||
this.eventMap[name] = listeners;
|
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) {
|
EventBaton.prototype.trigger = function(name) {
|
||||||
// arguments is weird and doesnt do slice right
|
// arguments is weird and doesnt do slice right
|
||||||
var argsToApply = [];
|
var argsToApply = this.sliceOffArgs(1, arguments);
|
||||||
for (var i = 1; i < arguments.length; i++) {
|
|
||||||
argsToApply.push(arguments[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var listeners = this.eventMap[name];
|
var listeners = this.eventMap[name];
|
||||||
if (!listeners || !listeners.length) {
|
if (!listeners || !listeners.length) {
|
||||||
console.warn('no listeners for', name);
|
console.warn('no listeners for', name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the top most listener with context and such
|
// call the top most listener with context and such
|
||||||
var toCall = listeners.slice(-1)[0];
|
var toCall = listeners.slice(-1)[0];
|
||||||
toCall.func.apply(toCall.context, argsToApply);
|
toCall.func.apply(toCall.context, argsToApply);
|
||||||
};
|
};
|
||||||
|
|
||||||
EventBaton.prototype.releaseBaton = function(name, func, context) {
|
EventBaton.prototype.getListenersThrow = function(name) {
|
||||||
if (!name) { throw new Error('need name'); }
|
|
||||||
// might be in the middle of the stack
|
|
||||||
var listeners = this.eventMap[name];
|
var listeners = this.eventMap[name];
|
||||||
if (!listeners || !listeners.length) {
|
if (!listeners || !listeners.length) {
|
||||||
throw new Error('no one has that baton!' + name);
|
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 newListeners = [];
|
||||||
var found = false;
|
var found = false;
|
||||||
|
|
|
@ -4,7 +4,6 @@ var Backbone = require('backbone');
|
||||||
|
|
||||||
var GRAPHICS = require('../util/constants').GRAPHICS;
|
var GRAPHICS = require('../util/constants').GRAPHICS;
|
||||||
var GLOBAL = require('../util/constants').GLOBAL;
|
var GLOBAL = require('../util/constants').GLOBAL;
|
||||||
var Main = require('../app');
|
|
||||||
|
|
||||||
var Collections = require('../models/collections');
|
var Collections = require('../models/collections');
|
||||||
var CommitCollection = Collections.CommitCollection;
|
var CommitCollection = Collections.CommitCollection;
|
||||||
|
@ -37,6 +36,7 @@ function GitVisuals(options) {
|
||||||
this.branchCollection.on('remove', this.removeBranch, this);
|
this.branchCollection.on('remove', this.removeBranch, this);
|
||||||
this.deferred = [];
|
this.deferred = [];
|
||||||
|
|
||||||
|
var Main = require('../app');
|
||||||
Main.getEvents().on('refreshTree', this.refreshTree, this);
|
Main.getEvents().on('refreshTree', this.refreshTree, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,6 +618,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
|
||||||
GitVisuals.prototype.canvasResize = _.debounce(function(width, height) {
|
GitVisuals.prototype.canvasResize = _.debounce(function(width, height) {
|
||||||
// refresh when we are ready
|
// refresh when we are ready
|
||||||
if (GLOBAL.isAnimating) {
|
if (GLOBAL.isAnimating) {
|
||||||
|
var Main = require('../app');
|
||||||
Main.getEventBaton().trigger('commandSubmitted', 'refresh');
|
Main.getEventBaton().trigger('commandSubmitted', 'refresh');
|
||||||
} else {
|
} else {
|
||||||
this.refreshTree();
|
this.refreshTree();
|
||||||
|
|
|
@ -27,6 +27,7 @@ var Visualization = Backbone.View.extend({
|
||||||
|
|
||||||
var Main = require('../app');
|
var Main = require('../app');
|
||||||
this.events = options.events || Main.getEvents();
|
this.events = options.events || Main.getEvents();
|
||||||
|
this.eventBaton = options.eventBaton || Main.getEventBaton();
|
||||||
|
|
||||||
this.commitCollection = new CommitCollection();
|
this.commitCollection = new CommitCollection();
|
||||||
this.branchCollection = new BranchCollection();
|
this.branchCollection = new BranchCollection();
|
||||||
|
@ -42,7 +43,7 @@ var Visualization = Backbone.View.extend({
|
||||||
collection: this.commitCollection,
|
collection: this.commitCollection,
|
||||||
branches: this.branchCollection,
|
branches: this.branchCollection,
|
||||||
gitVisuals: this.gitVisuals,
|
gitVisuals: this.gitVisuals,
|
||||||
events: this.events
|
eventBaton: this.eventBaton
|
||||||
});
|
});
|
||||||
this.gitEngine.init();
|
this.gitEngine.init();
|
||||||
this.gitVisuals.assignGitEngine(this.gitEngine);
|
this.gitVisuals.assignGitEngine(this.gitEngine);
|
||||||
|
|
7
todo.txt
7
todo.txt
|
@ -10,9 +10,6 @@ Medium things:
|
||||||
|
|
||||||
Commands
|
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:
|
Small things to implement:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -32,6 +29,10 @@ 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] 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] awesome ability to have dialogs and such handle command processing and block
|
||||||
[x] figure out why multiview baton passing doesn't work...
|
[x] figure out why multiview baton passing doesn't work...
|
||||||
[x] multiple things can process!!!
|
[x] multiple things can process!!!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue