(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./baseTypes"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const baseTypes_1 = require("./baseTypes");
    /**
     * Setups a timer and disposes automatically when view model is destroyed. This will execute
     * given function only once unless `repeat` argument is `true`.
     * @param delayInSeconds delay in seconds
     * @param repeat repeat at given delay
     */
    function Delay(delayInSeconds, repeat = false) {
        return (target, key) => {
            baseTypes_1.registerInit(target, (vm) => {
                // tslint:disable-next-line: ban-types
                const fx = vm[key];
                const afx = () => {
                    vm.app.runAsync(() => fx.apply(vm));
                };
                const dx = delayInSeconds * 1000;
                const id = repeat
                    ? setInterval(afx, dx)
                    : setTimeout(afx, dx);
                const d = {
                    dispose() {
                        if (repeat) {
                            clearInterval(id);
                        }
                        else {
                            clearTimeout(id);
                        }
                    }
                };
                vm.registerDisposable(d);
            });
        };
    }
    exports.default = Delay;
});
//# sourceMappingURL=Delay.js.map