mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-02 18:54:27 +02:00
explode animation based on promises
This commit is contained in:
parent
68ff9cebea
commit
9cb146462a
5 changed files with 174 additions and 1274 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue