Trying to be able to test in node GAHHHH

This commit is contained in:
Peter Cottle 2012-12-16 20:23:42 -08:00
parent c9fb851ad6
commit aadeab8299
14 changed files with 4186 additions and 69 deletions

File diff suppressed because it is too large Load diff

View file

@ -9,5 +9,10 @@
"grunt-jasmine-node": "latest",
"grunt-hash": "latest",
"grunt-rm": "~0.0.3"
},
"dependencies": {
"backbone": "~0.9.9",
"underscore": "~1.4.3",
"jquery": "~1.8.3"
}
}

View file

@ -1,3 +1,6 @@
var _ = require('underscore');
var Backbone = require('backbone');
/**
* Globals
*/

View file

@ -1,3 +1,8 @@
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var GitEngine = require('../git').GitEngine;
var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
var GitVisuals = require('../visuals').GitVisuals;
@ -25,7 +30,8 @@ HeadlessGit.prototype.init = function() {
collection: this.commitCollection,
branches: this.branchCollection,
gitVisuals: gitVisuals,
animationFactory: animationFactory
animationFactory: animationFactory,
events: _.clone(Backbone.Events)
});
this.gitEngine.init();
};

View file

@ -1,7 +1,10 @@
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var AnimationFactoryModule = require('../visuals/animation/animationFactory');
var Main = require('../app');
var AnimationQueue = require('../visuals/animation').AnimationQueue;
var InteractiveRebaseView = require('../views/miscViews').InteractiveRebaseView;
var Errors = require('../util/errors');
var GitError = Errors.GitError;
@ -23,6 +26,7 @@ function GitEngine(options) {
this.branchCollection = options.branches;
this.commitCollection = options.collection;
this.gitVisuals = options.gitVisuals;
this.events = options.events;
this.animationFactory = options.animationFactory ||
new AnimationFactoryModule.AnimationFactory();
@ -31,7 +35,7 @@ function GitEngine(options) {
this.commandOptions = {};
this.generalArgs = [];
Main.getEvents().on('processCommand', _.bind(this.dispatch, this));
this.events.on('processCommand', _.bind(this.dispatch, this));
}
GitEngine.prototype.defaultInit = function() {
@ -1014,6 +1018,7 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation)
this.animationQueue.start();
}, this);
var InteractiveRebaseView = require('../views/miscViews').InteractiveRebaseView;
new InteractiveRebaseView({
callback: callback,
toRebase: toRebase,

View file

@ -1,7 +1,11 @@
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var Commit = require('../git').Commit;
var Branch = require('../git').Branch;
var Main = require('../app');
var Command = require('../models/commandModel').Command;
var CommandEntry = require('../models/commandModel').CommandEntry;
var TIME = require('../util/constants').TIME;
@ -20,7 +24,7 @@ var BranchCollection = Backbone.Collection.extend({
var CommandEntryCollection = Backbone.Collection.extend({
model: CommandEntry,
localStorage: new Backbone.LocalStorage('CommandEntries')
localStorage: (Backbone.LocalStorage) ? new Backbone.LocalStorage('CommandEntries') : null
});
var CommandBuffer = Backbone.Model.extend({
@ -74,6 +78,7 @@ var CommandBuffer = Backbone.Model.extend({
}
if (!popped.get('error')) {
// pass in a callback, so when this command is "done" we will process the next.
var Main = require('../app');
Main.getEvents().trigger('processCommand', popped, callback);
} else {
this.clear();

View file

@ -1,3 +1,8 @@
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var Errors = require('../util/errors');
var CommandProcessError = Errors.CommandProcessError;
@ -363,10 +368,9 @@ var CommandEntry = Backbone.Model.extend({
defaults: {
text: ''
},
localStorage: new Backbone.LocalStorage('CommandEntries')
// stub out if no plugin available
localStorage: (Backbone.LocalStorage) ? new Backbone.LocalStorage('CommandEntries') : null
});
exports.CommandEntry = CommandEntry;
exports.Command = Command;

View file

@ -1,3 +1,8 @@
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var MyError = Backbone.Model.extend({
defaults: {
type: 'MyError',

4
src/js/util/index.js Normal file
View file

@ -0,0 +1,4 @@
exports.isBrowser = function() {
return (typeof window === undefined);
};

View file

@ -11,6 +11,11 @@
var Animation = require('./index').Animation;
var GRAPHICS = require('../../util/constants').GRAPHICS;
if (!require('../../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
// essentially a static class
var AnimationFactory = function() {

View file

@ -1,5 +1,10 @@
var GLOBAL = require('../../util/constants').GLOBAL;
if (!require('../../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var Animation = Backbone.Model.extend({
defaults: {
duration: 300,
@ -82,4 +87,3 @@ var AnimationQueue = Backbone.Model.extend({
exports.Animation = Animation;
exports.AnimationQueue = AnimationQueue;

View file

@ -1,4 +1,8 @@
var Main = require('../app');
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var GRAPHICS = require('../util/constants').GRAPHICS;
var GLOBAL = require('../util/constants').GLOBAL;
@ -27,6 +31,8 @@ var Visualization = Backbone.View.extend({
paperInitialize: function(paper, options) {
this.paper = paper;
var Main = require('../app');
this.events = Main.getEvents();
this.commitCollection = new CommitCollection();
this.branchCollection = new BranchCollection();
@ -41,7 +47,8 @@ var Visualization = Backbone.View.extend({
this.gitEngine = new GitEngine({
collection: this.commitCollection,
branches: this.branchCollection,
gitVisuals: this.gitVisuals
gitVisuals: this.gitVisuals,
events: this.events
});
this.gitEngine.init();
this.gitVisuals.assignGitEngine(this.gitEngine);
@ -91,7 +98,8 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = [];
Main.getEvents().on('refreshTree', _.bind(
this.events = require('../app').getEvents();
this.events.on('refreshTree', _.bind(
this.refreshTree, this
));
}
@ -536,7 +544,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
GitVisuals.prototype.canvasResize = _.debounce(function(width, height) {
// refresh when we are ready
if (GLOBAL.isAnimating) {
Main.getEvents().trigger('processCommandFromEvent', 'refresh');
this.events.trigger('processCommandFromEvent', 'refresh');
} else {
this.refreshTree();
}

View file

@ -1,4 +1,8 @@
var Main = require('../app');
if (!require('../util').isBrowser()) {
var _ = require('underscore');
var Backbone = require('backbone');
}
var GRAPHICS = require('../util/constants').GRAPHICS;
var randomHueString = function() {
@ -712,6 +716,7 @@ var VisNode = VisBase.extend({
attachClickHandlers: function() {
var commandStr = 'git show ' + this.get('commit').get('id');
var Main = require('../app');
_.each([this.get('circle'), this.get('text')], function(rObj) {
rObj.click(function() {
Main.getEvents().trigger('processCommandFromEvent', commandStr);

View file

@ -8,7 +8,7 @@ Big Graphic things:
Medium things:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
- gitEngine loads from tree immediately, not the weird thing we have now!
- headless git
- headless Git for testing (send it commands and expected trees)
Small things to implement:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~