UNPKG

@ncodedcode/ncode_react_lib

Version:

ncode react application context library

42 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NCPersistance = void 0; var NCStorage_1 = require("./NCStorage"); var Inject_1 = require("../../di/Inject"); var NCJsonSerializer_1 = require("../../utils/NCJsonSerializer"); var NCPersistance = (function () { function NCPersistance(isInstant) { if (isInstant === void 0) { isInstant = false; } this.storage = (0, Inject_1.Inject)(isInstant ? NCStorage_1.NCInstantStorageClassName : NCStorage_1.NCStorageClassName); } NCPersistance.prototype.put = function (key, value) { this.storage.save(key, value); }; NCPersistance.prototype.get = function (key, defaultValue) { if (defaultValue === void 0) { defaultValue = null; } return this.storage.load(key) || defaultValue; }; NCPersistance.prototype.delete = function (key) { return this.storage.delete(key); }; NCPersistance.prototype.putNumber = function (key, value) { this.put(key, value.toString()); }; NCPersistance.prototype.putObject = function (key, value) { this.put(key, NCJsonSerializer_1.NCJsonSerializer.encode(value)); }; NCPersistance.prototype.getNumber = function (key, defaultValue) { if (defaultValue === void 0) { defaultValue = 0; } return Number(this.get(key) || defaultValue); }; NCPersistance.prototype.getObject = function (key) { return this.get(key).then(function (json) { if (!json) return null; return NCJsonSerializer_1.NCJsonSerializer.decode(json); }); }; return NCPersistance; }()); exports.NCPersistance = NCPersistance; //# sourceMappingURL=NCPersistance.js.map