(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"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    if (typeof Map === "undefined") {
        var AtomMap = /** @class */ (function () {
            function AtomMap() {
                this.map = [];
            }
            Object.defineProperty(AtomMap.prototype, "size", {
                get: function () {
                    return this.map.length;
                },
                enumerable: false,
                configurable: true
            });
            AtomMap.prototype.clear = function () {
                this.map.length = 0;
            };
            AtomMap.prototype.delete = function (key) {
                return this.map.remove(function (x) { return x.key === key; });
            };
            AtomMap.prototype.forEach = function (callbackfn, thisArg) {
                for (var _i = 0, _a = this.map; _i < _a.length; _i++) {
                    var iterator = _a[_i];
                    callbackfn.call(thisArg, iterator.value, iterator.key, this);
                }
            };
            AtomMap.prototype.get = function (key) {
                var item = this.getItem(key, false);
                return item ? item.value : undefined;
            };
            AtomMap.prototype.has = function (key) {
                return this.map.find(function (x) { return x.key === key; }) != null;
            };
            AtomMap.prototype.set = function (key, value) {
                var item = this.getItem(key, true);
                item.value = value;
                return this;
            };
            // public [Symbol.iterator](): IterableIterator<[K, V]> {
            //     throw new Error("Method not implemented.");
            // }
            // public keys(): IterableIterator<K> {
            //     throw new Error("Method not implemented.");
            // }
            // public values(): IterableIterator<V> {
            //     throw new Error("Method not implemented.");
            // }
            // public get [Symbol.toStringTag](): string {
            //     return "[Map]";
            // }
            AtomMap.prototype.getItem = function (key, create) {
                if (create === void 0) { create = false; }
                for (var _i = 0, _a = this.map; _i < _a.length; _i++) {
                    var iterator = _a[_i];
                    if (iterator.key === key) {
                        return iterator;
                    }
                }
                if (create) {
                    var r = { key: key, value: undefined };
                    this.map.push(r);
                    return r;
                }
            };
            return AtomMap;
        }());
        // tslint:disable-next-line:no-string-literal
        window["Map"] = AtomMap;
    }
    // tslint:disable-next-line:only-arrow-functions
    Map.prototype.getOrCreate = function (key, factory) {
        var item = this.get(key);
        if (item === undefined) {
            item = factory(key);
            this.set(key, item);
        }
        return item;
    };
    exports.default = Map;
});
//# sourceMappingURL=AtomMap.js.map