mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-02 18:54:27 +02:00
in the midle of teamwork reorg why does promise not defer?
This commit is contained in:
parent
292126437a
commit
bf6f987482
4 changed files with 129 additions and 58 deletions
|
@ -44,7 +44,7 @@ GitEngine.prototype.initUniqueID = function() {
|
|||
this.uniqueId = (function() {
|
||||
var n = 0;
|
||||
return function(prepend) {
|
||||
return prepend? prepend + n++ : n++;
|
||||
return prepend ? prepend + n++ : n++;
|
||||
};
|
||||
})();
|
||||
};
|
||||
|
@ -837,15 +837,18 @@ GitEngine.prototype.fakeTeamworkStarter = function() {
|
|||
GitEngine.prototype.fakeTeamwork = function(numToMake) {
|
||||
var makeOriginCommit = _.bind(function() {
|
||||
var id = this.getUniqueID();
|
||||
this.origin.receiveTeamwork(id, this.animationQueue);
|
||||
return this.origin.receiveTeamwork(id, this.animationQueue);
|
||||
}, this);
|
||||
|
||||
var chainStep = function() {
|
||||
makeOriginCommit();
|
||||
var d = Q.defer();
|
||||
setTimeout(function() { d.resolve(); }, 1000);
|
||||
return d.promise;
|
||||
};
|
||||
var chainStep = _.bind(function() {
|
||||
var newCommit = makeOriginCommit();
|
||||
var animation = this.animationFactory.genCommitBirthPromiseAnimation(
|
||||
newCommit,
|
||||
this.origin.gitVisuals
|
||||
);
|
||||
animation.play();
|
||||
return animation.getPromise();
|
||||
}, this);
|
||||
|
||||
var deferred = Q.defer();
|
||||
var chain = deferred.promise;
|
||||
|
@ -865,7 +868,6 @@ GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
|||
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
||||
this.setTargetLocation(this.HEAD, newCommit);
|
||||
|
||||
//this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
||||
return newCommit;
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ var _ = require('underscore');
|
|||
var Backbone = require('backbone');
|
||||
|
||||
var Animation = require('./index').Animation;
|
||||
var PromiseAnimation = require('./index').PromiseAnimation;
|
||||
var GRAPHICS = require('../../util/constants').GRAPHICS;
|
||||
|
||||
/******************
|
||||
|
@ -19,19 +20,12 @@ var AnimationFactory = function() {
|
|||
|
||||
};
|
||||
|
||||
AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) {
|
||||
if (!animationQueue) {
|
||||
throw new Error("Need animation queue to add closure to!");
|
||||
}
|
||||
|
||||
var makeCommitBirthAnimation = function(gitVisuals, visNode) {
|
||||
var time = GRAPHICS.defaultAnimationTime * 1.0;
|
||||
var bounceTime = time * 2;
|
||||
|
||||
// essentially refresh the entire tree, but do a special thing for the commit
|
||||
var visNode = commit.get('visNode');
|
||||
|
||||
var animation = function() {
|
||||
// this takes care of refs and all that jazz, and updates all the positions
|
||||
// essentially refresh the entire tree, but do a special thing for the commit
|
||||
gitVisuals.refreshTree(time);
|
||||
|
||||
visNode.setBirth();
|
||||
|
@ -41,13 +35,36 @@ AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, co
|
|||
visNode.animateUpdatedPosition(bounceTime, 'bounce');
|
||||
visNode.animateOutgoingEdges(time);
|
||||
};
|
||||
return {
|
||||
animation: animation,
|
||||
duration: Math.max(time, bounceTime)
|
||||
};
|
||||
};
|
||||
|
||||
AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) {
|
||||
if (!animationQueue) {
|
||||
throw new Error("Need animation queue to add closure to!");
|
||||
}
|
||||
|
||||
var visNode = commit.get('visNode');
|
||||
var anPack = makeCommitBirthAnimation(gitVisuals, visNode);
|
||||
|
||||
animationQueue.add(new Animation({
|
||||
closure: animation,
|
||||
duration: Math.max(time, bounceTime)
|
||||
closure: anPack.animation,
|
||||
duration: anPack.duration
|
||||
}));
|
||||
};
|
||||
|
||||
AnimationFactory.prototype.genCommitBirthPromiseAnimation = function(commit, gitVisuals) {
|
||||
var visNode = commit.get('visNode');
|
||||
var anPack = makeCommitBirthAnimation(gitVisuals, visNode);
|
||||
console.log('my duration', anPack.duration);
|
||||
return new PromiseAnimation({
|
||||
closure: anPack.animation,
|
||||
duration: anPack.duration
|
||||
});
|
||||
};
|
||||
|
||||
AnimationFactory.prototype.overrideOpacityDepth2 = function(attr, opacity) {
|
||||
opacity = (opacity === undefined) ? 1 : opacity;
|
||||
|
||||
|
|
|
@ -102,6 +102,10 @@ var PromiseAnimation = Backbone.Model.extend({
|
|||
this.set('deferred', options.deferred || Q.defer());
|
||||
},
|
||||
|
||||
getPromise: function() {
|
||||
return this.get('deferred').promise;
|
||||
},
|
||||
|
||||
play: function() {
|
||||
// a single animation is just something with a timeout, but now
|
||||
// we want to resolve a deferred when the animation finishes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue