This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): ensure core animate runner is the same with and without an…
…imations The $$AnimateRunner class is now used as the same code within the core $animate service. Closes #13205
- Loading branch information
Showing
8 changed files
with
188 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
'use strict'; | ||
|
||
var $$AnimateAsyncRunFactoryProvider = function() { | ||
this.$get = ['$$rAF', function($$rAF) { | ||
var waitQueue = []; | ||
|
||
function waitForTick(fn) { | ||
waitQueue.push(fn); | ||
if (waitQueue.length > 1) return; | ||
$$rAF(function() { | ||
for (var i = 0; i < waitQueue.length; i++) { | ||
waitQueue[i](); | ||
} | ||
waitQueue = []; | ||
}); | ||
} | ||
|
||
return function() { | ||
var passed = false; | ||
waitForTick(function() { | ||
passed = true; | ||
}); | ||
return function(callback) { | ||
passed ? callback() : waitForTick(callback); | ||
}; | ||
}; | ||
}]; | ||
}; | ||
|
||
var $$AnimateRunnerFactoryProvider = function() { | ||
this.$get = ['$q', '$sniffer', '$$animateAsyncRun', | ||
function($q, $sniffer, $$animateAsyncRun) { | ||
|
||
var INITIAL_STATE = 0; | ||
var DONE_PENDING_STATE = 1; | ||
var DONE_COMPLETE_STATE = 2; | ||
|
||
AnimateRunner.chain = function(chain, callback) { | ||
var index = 0; | ||
|
||
next(); | ||
function next() { | ||
if (index === chain.length) { | ||
callback(true); | ||
return; | ||
} | ||
|
||
chain[index](function(response) { | ||
if (response === false) { | ||
callback(false); | ||
return; | ||
} | ||
index++; | ||
next(); | ||
}); | ||
} | ||
}; | ||
|
||
AnimateRunner.all = function(runners, callback) { | ||
var count = 0; | ||
var status = true; | ||
forEach(runners, function(runner) { | ||
runner.done(onProgress); | ||
}); | ||
|
||
function onProgress(response) { | ||
status = status && response; | ||
if (++count === runners.length) { | ||
callback(status); | ||
} | ||
} | ||
}; | ||
|
||
function AnimateRunner(host) { | ||
this.setHost(host); | ||
|
||
this._doneCallbacks = []; | ||
this._runInAnimationFrame = $$animateAsyncRun(); | ||
this._state = 0; | ||
} | ||
|
||
AnimateRunner.prototype = { | ||
setHost: function(host) { | ||
this.host = host || {}; | ||
}, | ||
|
||
done: function(fn) { | ||
if (this._state === DONE_COMPLETE_STATE) { | ||
fn(); | ||
} else { | ||
this._doneCallbacks.push(fn); | ||
} | ||
}, | ||
|
||
progress: noop, | ||
|
||
getPromise: function() { | ||
if (!this.promise) { | ||
var self = this; | ||
this.promise = $q(function(resolve, reject) { | ||
self.done(function(status) { | ||
status === false ? reject() : resolve(); | ||
}); | ||
}); | ||
} | ||
return this.promise; | ||
}, | ||
|
||
then: function(resolveHandler, rejectHandler) { | ||
return this.getPromise().then(resolveHandler, rejectHandler); | ||
}, | ||
|
||
'catch': function(handler) { | ||
return this.getPromise()['catch'](handler); | ||
}, | ||
|
||
'finally': function(handler) { | ||
return this.getPromise()['finally'](handler); | ||
}, | ||
|
||
pause: function() { | ||
if (this.host.pause) { | ||
this.host.pause(); | ||
} | ||
}, | ||
|
||
resume: function() { | ||
if (this.host.resume) { | ||
this.host.resume(); | ||
} | ||
}, | ||
|
||
end: function() { | ||
if (this.host.end) { | ||
this.host.end(); | ||
} | ||
this._resolve(true); | ||
}, | ||
|
||
cancel: function() { | ||
if (this.host.cancel) { | ||
this.host.cancel(); | ||
} | ||
this._resolve(false); | ||
}, | ||
|
||
complete: function(response) { | ||
var self = this; | ||
if (self._state === INITIAL_STATE) { | ||
self._state = DONE_PENDING_STATE; | ||
self._runInAnimationFrame(function() { | ||
self._resolve(response); | ||
}); | ||
} | ||
}, | ||
|
||
_resolve: function(response) { | ||
if (this._state !== DONE_COMPLETE_STATE) { | ||
forEach(this._doneCallbacks, function(fn) { | ||
fn(response); | ||
}); | ||
this._doneCallbacks.length = 0; | ||
this._state = DONE_COMPLETE_STATE; | ||
} | ||
} | ||
}; | ||
|
||
return AnimateRunner; | ||
}]; | ||
}; |
Oops, something went wrong.