explode animation based on promises

This commit is contained in:
Peter Cottle 2012-12-19 10:56:54 -08:00
parent 68ff9cebea
commit 9cb146462a
5 changed files with 174 additions and 1274 deletions

View file

@ -1,4 +1,5 @@
var _ = require('underscore');
var Q = require('q');
// horrible hack to get localStorage Backbone plugin
var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone;
@ -119,6 +120,49 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
};
};
GitVisuals.prototype.finishAnimation = function() {
var deferred = Q.defer();
deferred.promise
.then(_.bind(this.explodeNodes, this))
.then(_.bind(this.
deferred.resolve();
};
GitVisuals.prototype.explodeNodes = function() {
var deferred = Q.defer();
var funcs = [];
_.each(this.visNodeMap, function(visNode) {
funcs.push(visNode.getExplodeStepFunc());
});
var interval = setInterval(function() {
// object creation here is a bit ugly inside a loop,
// but the alternative is to just OR against a bunch
// of booleans which means the other stepFuncs
// are called unnecessarily when they have almost
// zero speed. would be interesting to see performance differences
var keepGoing = [];
_.each(funcs, function(func) {
if (func()) {
keepGoing.push(func);
}
});
if (!keepGoing.length) {
clearInterval(interval);
// next step :D wow I love promises
deferred.resolve();
return;
}
funcs = keepGoing;
}, 1/40);
return deferred.promise;
};
GitVisuals.prototype.animateAllFromAttrToAttr = function(fromSnapshot, toSnapshot, idsToOmit) {
var animate = function(obj) {
var id = obj.getID();