You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
538 B
31 lines
538 B
import raf from 'raf';
|
|
|
|
let id = 0;
|
|
const ids = {};
|
|
|
|
// Support call raf with delay specified frame
|
|
export default function wrapperRaf(callback, delayFrames = 1) {
|
|
const myId = id++;
|
|
let restFrames = delayFrames;
|
|
|
|
function internalCallback() {
|
|
restFrames -= 1;
|
|
|
|
if (restFrames <= 0) {
|
|
callback();
|
|
delete ids[id];
|
|
} else {
|
|
ids[id] = raf(internalCallback);
|
|
}
|
|
}
|
|
|
|
ids[id] = raf(internalCallback);
|
|
|
|
return myId;
|
|
}
|
|
|
|
wrapperRaf.cancel = function(pid) {
|
|
raf.cancel(ids[pid]);
|
|
delete ids[pid];
|
|
};
|