assassin-bug/framework/scheduler/raf.js

25 lines
532 B
JavaScript
Raw Permalink Normal View History

2022-11-26 01:22:02 +00:00
export class RAFTimer {
constructor(node) {
this.isStarted = false;
this.node = node;
}
start() {
this.isStarted = true;
this.schedule();
}
stop() {
this.isStarted = false;
}
schedule() {
window.requestAnimationFrame(this.handleResolve.bind(this));
}
handleResolve() {
if (this.node) {
this.node.func(1);
if (this.isStarted) {
this.schedule();
}
}
}
}