import { vglobal } from "../modules";

export class PerformanceRAF {
    constructor() {
        this.nextAnimationFrameCbs = [], this._rafHandle = null, this.runAnimationFrame = time => {
            this._rafHandle = null;
            const cbs = this.nextAnimationFrameCbs;
            this.nextAnimationFrameCbs = [];
            for (let i = 0; i < cbs.length; i++) cbs[i] && cbs[i](time);
        }, this.tryRunAnimationFrameNextFrame = () => {
            null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.length && (this._rafHandle = vglobal.getRequestAnimationFrame()(this.runAnimationFrame));
        };
    }
    addAnimationFrameCb(callback) {
        return this.nextAnimationFrameCbs.push(callback), this.tryRunAnimationFrameNextFrame(), 
        this.nextAnimationFrameCbs.length - 1;
    }
    removeAnimationFrameCb(index) {
        return index >= 0 && index < this.nextAnimationFrameCbs.length && (this.nextAnimationFrameCbs[index] = null, 
        !0);
    }
}
//# sourceMappingURL=performance-raf.js.map