(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 });
    var 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) {
        if (repeat === void 0) { repeat = false; }
        return function (target, key) {
            baseTypes_1.registerInit(target, function (vm) {
                // tslint:disable-next-line: ban-types
                var fx = vm[key];
                var afx = function () {
                    vm.app.runAsync(function () { return fx.apply(vm); });
                };
                var dx = delayInSeconds * 1000;
                var id = repeat
                    ? setInterval(afx, dx)
                    : setTimeout(afx, dx);
                var d = {
                    dispose: function () {
                        if (repeat) {
                            clearInterval(id);
                        }
                        else {
                            clearTimeout(id);
                        }
                    }
                };
                vm.registerDisposable(d);
            });
        };
    }
    exports.default = Delay;
});
//# sourceMappingURL=Delay.js.map