"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Direct_1 = require("./Direct");
var Defered = /** @class */ (function (_super) {
    tslib_1.__extends(Defered, _super);
    function Defered() {
        var _this = _super.call(this) || this;
        _this.redrawQueued = false;
        _this.requestRedraw = _this.requestRedraw.bind(_this);
        _this.framedRedraw = _this.framedRedraw.bind(_this);
        return _this;
    }
    Defered.prototype.requestRedraw = function (force) {
        if (force === true) {
            if (this.animationFrame !== undefined) {
                window.cancelAnimationFrame(this.animationFrame);
            }
            this.framedRedraw();
            return;
        }
        if (this.redrawQueued) {
            return;
        }
        this.redrawQueued = true;
        this.animationFrame = window.requestAnimationFrame(this.framedRedraw);
    };
    Defered.prototype.cancelRedraw = function () {
        if (this.animationFrame !== undefined) {
            window.cancelAnimationFrame(this.animationFrame);
            this.animationFrame = undefined;
        }
    };
    Defered.prototype.framedRedraw = function () {
        this.redraw();
        this.redrawQueued = false;
        this.animationFrame = undefined;
    };
    Defered.prototype.redraw = function () {
        _super.prototype.requestRedraw.call(this, true);
    };
    return Defered;
}(Direct_1.Direct));
exports.Defered = Defered;
