1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9 |
|
10 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
11 |
|
12 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
13 |
|
14 | var Cache = function () {
|
15 | function Cache() {
|
16 | _classCallCheck(this, Cache);
|
17 |
|
18 | this._root = null;
|
19 | this._store = new Map();
|
20 | }
|
21 |
|
22 | _createClass(Cache, [{
|
23 | key: "empty",
|
24 | value: function empty() {
|
25 | return this._store.size === 0;
|
26 | }
|
27 | }, {
|
28 | key: "has",
|
29 | value: function has(key) {
|
30 | return this._store.has(key);
|
31 | }
|
32 | }, {
|
33 | key: "get",
|
34 | value: function get(key, defaultValue) {
|
35 | var res = this.has(key) ? this._store.get(key) : this.root();
|
36 | return typeof res === 'undefined' || res === null ? defaultValue : res;
|
37 | }
|
38 | }, {
|
39 | key: "add",
|
40 | value: function add(key, value) {
|
41 | if (this.empty()) {
|
42 | this._root = key;
|
43 | }
|
44 |
|
45 | this._store.set(key, value);
|
46 | }
|
47 | }, {
|
48 | key: "update",
|
49 | value: function update(key, value) {
|
50 | if (this.has(key)) {
|
51 | this._store.set(key, value);
|
52 | }
|
53 | }
|
54 | }, {
|
55 | key: "remove",
|
56 | value: function remove(key) {
|
57 | this._store["delete"](key);
|
58 | }
|
59 | }, {
|
60 | key: "root",
|
61 | value: function root() {
|
62 | return this._store.get(this._root);
|
63 | }
|
64 | }]);
|
65 |
|
66 | return Cache;
|
67 | }();
|
68 |
|
69 | var _default = Cache;
|
70 | exports["default"] = _default; |
\ | No newline at end of file |