From bf6f9874820c516645312c7fef7dd4bd2e266a50 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Sun, 2 Jun 2013 17:16:14 -0700 Subject: [PATCH] in the midle of teamwork reorg why does promise not defer? --- build/bundle.js | 124 +++++++++++++------ src/js/git/index.js | 20 +-- src/js/visuals/animation/animationFactory.js | 39 ++++-- src/js/visuals/animation/index.js | 4 + 4 files changed, 129 insertions(+), 58 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index d7e6bb1b..552343d9 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -7890,15 +7890,19 @@ 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(); + console.log('playing animation'); + return animation.getPromise(); + }, this); var deferred = Q.defer(); var chain = deferred.promise; @@ -7918,7 +7922,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; }; @@ -9143,6 +9146,7 @@ require.define("/src/js/visuals/animation/animationFactory.js",function(require, var Backbone = require('backbone'); var Animation = require('./index').Animation; +var PromiseAnimation = require('./index').PromiseAnimation; var GRAPHICS = require('../../util/constants').GRAPHICS; /****************** @@ -9160,19 +9164,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(); @@ -9182,13 +9179,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; @@ -9505,6 +9525,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 @@ -23768,15 +23792,19 @@ 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(); + console.log('playing animation'); + return animation.getPromise(); + }, this); var deferred = Q.defer(); var chain = deferred.promise; @@ -23796,7 +23824,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; }; @@ -31224,6 +31251,7 @@ require.define("/src/js/visuals/animation/animationFactory.js",function(require, var Backbone = require('backbone'); var Animation = require('./index').Animation; +var PromiseAnimation = require('./index').PromiseAnimation; var GRAPHICS = require('../../util/constants').GRAPHICS; /****************** @@ -31241,19 +31269,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(); @@ -31263,13 +31284,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; @@ -31587,6 +31631,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 diff --git a/src/js/git/index.js b/src/js/git/index.js index 12559448..61b124e9 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -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; }; diff --git a/src/js/visuals/animation/animationFactory.js b/src/js/visuals/animation/animationFactory.js index 9331ac85..e77aa53e 100644 --- a/src/js/visuals/animation/animationFactory.js +++ b/src/js/visuals/animation/animationFactory.js @@ -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; diff --git a/src/js/visuals/animation/index.js b/src/js/visuals/animation/index.js index f3b81c68..c2ab5ff1 100644 --- a/src/js/visuals/animation/index.js +++ b/src/js/visuals/animation/index.js @@ -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