tsbase
Version:
Base class libraries for TypeScript
40 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryStorage = void 0;
const Command_1 = require("../../Patterns/CommandQuery/Command");
const Query_1 = require("../../Patterns/CommandQuery/Query");
/**
* Provides a generic interface for storing values in an in-memory Map object
*/
class InMemoryStorage {
constructor() {
this.storageMap = new Map();
}
Get(_type, key) {
return this.GetValue(key);
}
Set(key, value) {
return new Command_1.Command(() => {
this.storageMap.set(key, value);
}).Execute();
}
GetValue(key) {
return new Query_1.Query(() => {
const value = this.storageMap.get(key);
if (value) {
return value;
}
else {
return null;
}
}).Execute();
}
SetValue(key, value) {
return this.Set(key, value);
}
Remove(key) {
return new Command_1.Command(() => this.storageMap.delete(key)).Execute();
}
}
exports.InMemoryStorage = InMemoryStorage;
//# sourceMappingURL=InMemoryStorage.js.map