qt-public-ui
Version:
新设计规范下业务组件库
29 lines (28 loc) • 678 B
JavaScript
import raf from 'raf';
var id = 0;
var ids = {};
// Support call raf with delay specified frame
export default function wrapperRaf(callback, delayFrames) {
if (delayFrames === void 0) {
delayFrames = 1;
}
var myId = id++;
var restFrames = delayFrames;
function internalCallback() {
restFrames -= 1;
if (restFrames <= 0) {
callback();
delete ids[myId];
} else {
ids[myId] = raf(internalCallback);
}
}
ids[myId] = raf(internalCallback);
return myId;
}
wrapperRaf.cancel = function cancel(pid) {
if (pid === undefined) return;
raf.cancel(ids[pid]);
delete ids[pid];
};
wrapperRaf.ids = ids; // export this for test usage