Skip to content

Commit

Permalink
Merge pull request #168 from canjs/cancel-af
Browse files Browse the repository at this point in the history
Adds cancelAnimationFrame
  • Loading branch information
matthewp committed Apr 14, 2018
2 parents 20062f9 + bd61832 commit 3d75e2e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6,950 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
20 changes: 18 additions & 2 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,24 @@ exports.clearImmediate = function(clearImmediate, Zone){

exports.requestAnimationFrame = function(rAF, Zone){
return function(fn){
var callback = Zone.current.waitFor(fn);
return rAF.call(this, callback);
var zone = Zone.current;
var callback = zone.waitFor(fn);
var id = rAF.call(this, callback);
zone.rafs[id] = true;
return id;
};
};

exports.cancelAnimationFrame = function(cAF, Zone){
return function(id){
var zone = Zone.current;
var ids = zone.rafs;
var res = cAF.call(this, id);
if(!zone.isResolved && ids[id]) {
delete ids[id];
zone.removeWait();
}
return res;
};
};

Expand Down
3 changes: 2 additions & 1 deletion lib/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ function Zone(spec) {
spec = spec || {};
this.deferred = new Deferred();
this.waits = 0;
this.ids = {};
this.ids = Object.create(null);
this.rafs = Object.create(null);
this.errors = [];
this.data = {};
this.globals = {};
Expand Down
Loading

0 comments on commit 3d75e2e

Please sign in to comment.