before headless fix, but not animation factory is static class

This commit is contained in:
Peter Cottle 2013-06-05 18:48:59 -10:00
parent a7e515dd8c
commit d0e206bcc4
4 changed files with 56 additions and 49 deletions

View file

@ -7058,7 +7058,7 @@ var Q = require('q');
var intl = require('../intl'); var intl = require('../intl');
var AnimationFactoryModule = require('../visuals/animation/animationFactory'); var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
var AnimationQueue = require('../visuals/animation').AnimationQueue; var AnimationQueue = require('../visuals/animation').AnimationQueue;
var TreeCompare = require('./treeCompare').TreeCompare; var TreeCompare = require('./treeCompare').TreeCompare;
@ -7081,8 +7081,9 @@ function GitEngine(options) {
this.eventBaton = options.eventBaton; this.eventBaton = options.eventBaton;
this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); this.eventBaton.stealBaton('processGitCommand', this.dispatch, this);
// poor man's dependency injection
this.animationFactory = options.animationFactory || this.animationFactory = options.animationFactory ||
new AnimationFactoryModule.AnimationFactory(); AnimationFactory;
// global variable to keep track of the options given // global variable to keep track of the options given
// along with the command call. // along with the command call.
@ -9136,10 +9137,8 @@ var GRAPHICS = require('../../util/constants').GRAPHICS;
* and then essentially animate the entire tree too. * and then essentially animate the entire tree too.
*/ */
// essentially a static class // static class
var AnimationFactory = function() { var AnimationFactory = {};
};
var makeCommitBirthAnimation = function(gitVisuals, visNode) { var makeCommitBirthAnimation = function(gitVisuals, visNode) {
var time = GRAPHICS.defaultAnimationTime * 1.0; var time = GRAPHICS.defaultAnimationTime * 1.0;
@ -9174,7 +9173,7 @@ var makeHighlightAnimation = function(visNode, visBranch) {
}; };
}; };
AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { AnimationFactory.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) {
if (!animationQueue) { if (!animationQueue) {
throw new Error("Need animation queue to add closure to!"); throw new Error("Need animation queue to add closure to!");
} }
@ -9188,12 +9187,12 @@ AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, co
})); }));
}; };
AnimationFactory.prototype.genCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.genCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode)); return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode));
}; };
AnimationFactory.prototype.highlightEachWithPromise = function( AnimationFactory.highlightEachWithPromise = function(
chain, chain,
toHighlight, toHighlight,
destObj destObj
@ -9209,13 +9208,13 @@ AnimationFactory.prototype.highlightEachWithPromise = function(
return chain; return chain;
}; };
AnimationFactory.prototype.playCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.playCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals); var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) { AnimationFactory.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -9225,7 +9224,7 @@ AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals,
animationQueue.thenFinish(animation.getPromise()); animationQueue.thenFinish(animation.getPromise());
}; };
AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) { AnimationFactory.playRefreshAnimation = function(gitVisuals) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -9235,7 +9234,7 @@ AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) {
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) { AnimationFactory.refreshTree = function(animationQueue, gitVisuals) {
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -9243,20 +9242,20 @@ AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) {
})); }));
}; };
AnimationFactory.prototype.genHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.genHighlightPromiseAnimation = function(commit, destObj) {
// could be branch or node // could be branch or node
var visObj = destObj.get('visBranch') || destObj.get('visNode'); var visObj = destObj.get('visBranch') || destObj.get('visNode');
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeHighlightAnimation(visNode, visObj)); return new PromiseAnimation(makeHighlightAnimation(visNode, visObj));
}; };
AnimationFactory.prototype.playHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.playHighlightPromiseAnimation = function(commit, destObj) {
var animation = this.genHighlightPromiseAnimation(commit, destObj); var animation = this.genHighlightPromiseAnimation(commit, destObj);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.delay = function(animationQueue, time) { AnimationFactory.delay = function(animationQueue, time) {
time = time || GRAPHICS.defaultAnimationTime; time = time || GRAPHICS.defaultAnimationTime;
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { }, closure: function() { },
@ -22855,7 +22854,7 @@ var Q = require('q');
var intl = require('../intl'); var intl = require('../intl');
var AnimationFactoryModule = require('../visuals/animation/animationFactory'); var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
var AnimationQueue = require('../visuals/animation').AnimationQueue; var AnimationQueue = require('../visuals/animation').AnimationQueue;
var TreeCompare = require('./treeCompare').TreeCompare; var TreeCompare = require('./treeCompare').TreeCompare;
@ -22878,8 +22877,9 @@ function GitEngine(options) {
this.eventBaton = options.eventBaton; this.eventBaton = options.eventBaton;
this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); this.eventBaton.stealBaton('processGitCommand', this.dispatch, this);
// poor man's dependency injection
this.animationFactory = options.animationFactory || this.animationFactory = options.animationFactory ||
new AnimationFactoryModule.AnimationFactory(); AnimationFactory;
// global variable to keep track of the options given // global variable to keep track of the options given
// along with the command call. // along with the command call.
@ -31136,10 +31136,8 @@ var GRAPHICS = require('../../util/constants').GRAPHICS;
* and then essentially animate the entire tree too. * and then essentially animate the entire tree too.
*/ */
// essentially a static class // static class
var AnimationFactory = function() { var AnimationFactory = {};
};
var makeCommitBirthAnimation = function(gitVisuals, visNode) { var makeCommitBirthAnimation = function(gitVisuals, visNode) {
var time = GRAPHICS.defaultAnimationTime * 1.0; var time = GRAPHICS.defaultAnimationTime * 1.0;
@ -31174,7 +31172,7 @@ var makeHighlightAnimation = function(visNode, visBranch) {
}; };
}; };
AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { AnimationFactory.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) {
if (!animationQueue) { if (!animationQueue) {
throw new Error("Need animation queue to add closure to!"); throw new Error("Need animation queue to add closure to!");
} }
@ -31188,12 +31186,12 @@ AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, co
})); }));
}; };
AnimationFactory.prototype.genCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.genCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode)); return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode));
}; };
AnimationFactory.prototype.highlightEachWithPromise = function( AnimationFactory.highlightEachWithPromise = function(
chain, chain,
toHighlight, toHighlight,
destObj destObj
@ -31209,13 +31207,13 @@ AnimationFactory.prototype.highlightEachWithPromise = function(
return chain; return chain;
}; };
AnimationFactory.prototype.playCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.playCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals); var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) { AnimationFactory.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -31225,7 +31223,7 @@ AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals,
animationQueue.thenFinish(animation.getPromise()); animationQueue.thenFinish(animation.getPromise());
}; };
AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) { AnimationFactory.playRefreshAnimation = function(gitVisuals) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -31235,7 +31233,7 @@ AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) {
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) { AnimationFactory.refreshTree = function(animationQueue, gitVisuals) {
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -31243,20 +31241,20 @@ AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) {
})); }));
}; };
AnimationFactory.prototype.genHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.genHighlightPromiseAnimation = function(commit, destObj) {
// could be branch or node // could be branch or node
var visObj = destObj.get('visBranch') || destObj.get('visNode'); var visObj = destObj.get('visBranch') || destObj.get('visNode');
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeHighlightAnimation(visNode, visObj)); return new PromiseAnimation(makeHighlightAnimation(visNode, visObj));
}; };
AnimationFactory.prototype.playHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.playHighlightPromiseAnimation = function(commit, destObj) {
var animation = this.genHighlightPromiseAnimation(commit, destObj); var animation = this.genHighlightPromiseAnimation(commit, destObj);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.delay = function(animationQueue, time) { AnimationFactory.delay = function(animationQueue, time) {
time = time || GRAPHICS.defaultAnimationTime; time = time || GRAPHICS.defaultAnimationTime;
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { }, closure: function() { },

View file

@ -16,6 +16,16 @@ var Command = require('../models/commandModel').Command;
var mock = require('../util/mock').mock; var mock = require('../util/mock').mock;
var util = require('../util'); var util = require('../util');
function getMockFactory() {
var mockFactory = {};
for (var key in AnimationFactory) {
mockFactory[key] = function() {
return Q.defer().promise;
};
}
return mockFactory;
}
var HeadlessGit = function() { var HeadlessGit = function() {
this.init(); this.init();
}; };
@ -27,7 +37,7 @@ HeadlessGit.prototype.init = function() {
// here we mock visuals and animation factory so the git engine // here we mock visuals and animation factory so the git engine
// is headless // is headless
var animationFactory = mock(AnimationFactory); var animationFactory = getMockFactory();
var gitVisuals = mock(GitVisuals); var gitVisuals = mock(GitVisuals);
this.gitEngine = new GitEngine({ this.gitEngine = new GitEngine({

View file

@ -5,7 +5,7 @@ var Q = require('q');
var intl = require('../intl'); var intl = require('../intl');
var AnimationFactoryModule = require('../visuals/animation/animationFactory'); var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
var AnimationQueue = require('../visuals/animation').AnimationQueue; var AnimationQueue = require('../visuals/animation').AnimationQueue;
var TreeCompare = require('./treeCompare').TreeCompare; var TreeCompare = require('./treeCompare').TreeCompare;
@ -28,8 +28,9 @@ function GitEngine(options) {
this.eventBaton = options.eventBaton; this.eventBaton = options.eventBaton;
this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); this.eventBaton.stealBaton('processGitCommand', this.dispatch, this);
// poor man's dependency injection
this.animationFactory = options.animationFactory || this.animationFactory = options.animationFactory ||
new AnimationFactoryModule.AnimationFactory(); AnimationFactory;
// global variable to keep track of the options given // global variable to keep track of the options given
// along with the command call. // along with the command call.

View file

@ -15,10 +15,8 @@ var GRAPHICS = require('../../util/constants').GRAPHICS;
* and then essentially animate the entire tree too. * and then essentially animate the entire tree too.
*/ */
// essentially a static class // static class
var AnimationFactory = function() { var AnimationFactory = {};
};
var makeCommitBirthAnimation = function(gitVisuals, visNode) { var makeCommitBirthAnimation = function(gitVisuals, visNode) {
var time = GRAPHICS.defaultAnimationTime * 1.0; var time = GRAPHICS.defaultAnimationTime * 1.0;
@ -53,7 +51,7 @@ var makeHighlightAnimation = function(visNode, visBranch) {
}; };
}; };
AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { AnimationFactory.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) {
if (!animationQueue) { if (!animationQueue) {
throw new Error("Need animation queue to add closure to!"); throw new Error("Need animation queue to add closure to!");
} }
@ -67,12 +65,12 @@ AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, co
})); }));
}; };
AnimationFactory.prototype.genCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.genCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode)); return new PromiseAnimation(makeCommitBirthAnimation(gitVisuals, visNode));
}; };
AnimationFactory.prototype.highlightEachWithPromise = function( AnimationFactory.highlightEachWithPromise = function(
chain, chain,
toHighlight, toHighlight,
destObj destObj
@ -88,13 +86,13 @@ AnimationFactory.prototype.highlightEachWithPromise = function(
return chain; return chain;
}; };
AnimationFactory.prototype.playCommitBirthPromiseAnimation = function(commit, gitVisuals) { AnimationFactory.playCommitBirthPromiseAnimation = function(commit, gitVisuals) {
var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals); var animation = this.genCommitBirthPromiseAnimation(commit, gitVisuals);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) { AnimationFactory.playRefreshAnimationAndFinish = function(gitVisuals, animationQueue) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -104,7 +102,7 @@ AnimationFactory.prototype.playRefreshAnimationAndFinish = function(gitVisuals,
animationQueue.thenFinish(animation.getPromise()); animationQueue.thenFinish(animation.getPromise());
}; };
AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) { AnimationFactory.playRefreshAnimation = function(gitVisuals) {
var animation = new PromiseAnimation({ var animation = new PromiseAnimation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -114,7 +112,7 @@ AnimationFactory.prototype.playRefreshAnimation = function(gitVisuals) {
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) { AnimationFactory.refreshTree = function(animationQueue, gitVisuals) {
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { closure: function() {
gitVisuals.refreshTree(); gitVisuals.refreshTree();
@ -122,20 +120,20 @@ AnimationFactory.prototype.refreshTree = function(animationQueue, gitVisuals) {
})); }));
}; };
AnimationFactory.prototype.genHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.genHighlightPromiseAnimation = function(commit, destObj) {
// could be branch or node // could be branch or node
var visObj = destObj.get('visBranch') || destObj.get('visNode'); var visObj = destObj.get('visBranch') || destObj.get('visNode');
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return new PromiseAnimation(makeHighlightAnimation(visNode, visObj)); return new PromiseAnimation(makeHighlightAnimation(visNode, visObj));
}; };
AnimationFactory.prototype.playHighlightPromiseAnimation = function(commit, destObj) { AnimationFactory.playHighlightPromiseAnimation = function(commit, destObj) {
var animation = this.genHighlightPromiseAnimation(commit, destObj); var animation = this.genHighlightPromiseAnimation(commit, destObj);
animation.play(); animation.play();
return animation.getPromise(); return animation.getPromise();
}; };
AnimationFactory.prototype.delay = function(animationQueue, time) { AnimationFactory.delay = function(animationQueue, time) {
time = time || GRAPHICS.defaultAnimationTime; time = time || GRAPHICS.defaultAnimationTime;
animationQueue.add(new Animation({ animationQueue.add(new Animation({
closure: function() { }, closure: function() { },