@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
24 lines (22 loc) • 990 B
JavaScript
import { application } from "../application";
let idx = 0;
export class PerformanceRAF {
constructor() {
this.nextAnimationFrameCbs = new Map, this._rafHandle = null, this.runAnimationFrame = time => {
this._rafHandle = null;
const cbs = this.nextAnimationFrameCbs;
this.nextAnimationFrameCbs = new Map, cbs.forEach((cb => cb(time)));
}, this.tryRunAnimationFrameNextFrame = () => {
null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.size && (this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame));
};
}
addAnimationFrameCb(callback) {
return this.nextAnimationFrameCbs.set(++idx, callback), this.tryRunAnimationFrameNextFrame(),
idx;
}
removeAnimationFrameCb(index) {
return !!this.nextAnimationFrameCbs.has(index) && (this.nextAnimationFrameCbs.delete(index),
!0);
}
}
//# sourceMappingURL=performance-raf.js.map