export class RAFTimer {
    constructor(node) {
        this.lastTime = 0;
        this.currTime = 0;
        this.isStarted = false;
        this.node = node;
    }
    start() {
        this.isStarted = true;
        this.schedule();
    }
    stop() {
        this.isStarted = false;
    }
    schedule() {
        window.requestAnimationFrame(this.handleResolve.bind(this));
    }
    handleResolve(dt) {
        if (this.node) {
            if (!this.lastTime) {
                this.lastTime = dt;
                this.node.func(1);
            }
            else {
                const delta = dt - this.lastTime;
                this.lastTime = dt;
                this.node.func(delta / 1000);
            }
            if (this.isStarted) {
                this.schedule();
            }
        }
    }
}
