"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const _ids_1 = require("../../../../_ids");
class RequestAnimationFrame extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['a'],
            o: ['a'],
        }, {}, system, _ids_1.ID_REQUEST_ANIMATION_FRAME);
        this._frame = undefined;
        this.addListener('reset', () => {
            this._reset();
        });
        this.addListener('destroy', () => {
            this._reset();
        });
    }
    _reset() {
        const { api: { animation: { cancelAnimationFrame }, }, } = this.__system;
        if (this._frame) {
            cancelAnimationFrame(this._frame);
            this._frame = undefined;
        }
    }
    f({ a }, done) {
        const { api: { animation: { requestAnimationFrame }, }, } = this.__system;
        if (requestAnimationFrame) {
            this._reset();
            this._frame = requestAnimationFrame(() => {
                this._frame = undefined;
                done({ a });
            });
        }
        else {
            done(undefined, 'request animation frame not supported');
        }
    }
}
exports.default = RequestAnimationFrame;
//# sourceMappingURL=index.js.map