(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", "reflect-metadata"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    require("reflect-metadata");
    /**
     *
     *
     * @export
     * @class CancelToken
     */
    var CancelToken = /** @class */ (function () {
        function CancelToken(timeout) {
            var _this = this;
            if (timeout === void 0) { timeout = -1; }
            this.listeners = [];
            this.mCancelled = null;
            this.cancelTimeout = null;
            if (timeout > 0) {
                this.cancelTimeout = setTimeout(function () {
                    _this.cancelTimeout = null;
                    _this.cancel("timeout");
                }, timeout);
            }
        }
        Object.defineProperty(CancelToken.prototype, "cancelled", {
            get: function () {
                return this.mCancelled;
            },
            enumerable: true,
            configurable: true
        });
        CancelToken.prototype.cancel = function (r) {
            if (r === void 0) { r = "cancelled"; }
            this.mCancelled = r;
            var existing = this.listeners.slice(0);
            this.listeners.length = 0;
            for (var _i = 0, existing_1 = existing; _i < existing_1.length; _i++) {
                var fx = existing_1[_i];
                fx(r);
            }
            this.dispose();
        };
        CancelToken.prototype.reset = function () {
            this.mCancelled = null;
            this.dispose();
        };
        CancelToken.prototype.dispose = function () {
            this.listeners.length = 0;
            if (this.cancelTimeout) {
                clearTimeout(this.cancelTimeout);
            }
        };
        CancelToken.prototype.registerForCancel = function (f) {
            if (this.mCancelled) {
                f(this.mCancelled);
                this.cancel();
                return;
            }
            this.listeners.push(f);
        };
        return CancelToken;
    }());
    exports.CancelToken = CancelToken;
    var ArrayHelper = /** @class */ (function () {
        function ArrayHelper() {
        }
        ArrayHelper.remove = function (a, filter) {
            for (var i = 0; i < a.length; i++) {
                var item = a[i];
                if (filter(item)) {
                    a.splice(i, 1);
                    return true;
                }
            }
            return false;
        };
        return ArrayHelper;
    }());
    exports.ArrayHelper = ArrayHelper;
    var globalNS = (typeof window !== "undefined" ? window : global);
    exports.DI = (globalNS).UMD;
    exports.UMD = (globalNS).UMD;
});
//# sourceMappingURL=types.js.map