UNPKG

tsbase

Version:

Base class libraries for TypeScript

46 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InMemoryStorage = void 0; var Command_1 = require("../../Patterns/CommandQuery/Command"); var Query_1 = require("../../Patterns/CommandQuery/Query"); /** * Provides a generic interface for storing values in an in-memory Map object */ var InMemoryStorage = /** @class */ (function () { function InMemoryStorage() { this.storageMap = new Map(); } InMemoryStorage.prototype.Get = function (_type, key) { return this.GetValue(key); }; InMemoryStorage.prototype.Set = function (key, value) { var _this = this; return new Command_1.Command(function () { _this.storageMap.set(key, value); }).Execute(); }; InMemoryStorage.prototype.GetValue = function (key) { var _this = this; return new Query_1.Query(function () { var value = _this.storageMap.get(key); if (value) { return value; } else { return null; } }).Execute(); }; InMemoryStorage.prototype.SetValue = function (key, value) { return this.Set(key, value); }; InMemoryStorage.prototype.Remove = function (key) { var _this = this; return new Command_1.Command(function () { return _this.storageMap.delete(key); }).Execute(); }; return InMemoryStorage; }()); exports.InMemoryStorage = InMemoryStorage; //# sourceMappingURL=InMemoryStorage.js.map