@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
32 lines (27 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.PerformanceRAF = void 0;
const application_1 = require("../application");
let idx = 0;
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_1.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);
}
}
exports.PerformanceRAF = PerformanceRAF;
//# sourceMappingURL=performance-raf.js.map