1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | /* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
3 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
4 | /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
5 | /**
|
6 | * Memo class used for decycle json objects. Uses WeakSet if available otherwise array.
|
7 | */
|
8 | var Memo = /** @class */ (function () {
|
9 | function Memo() {
|
10 | this._hasWeakSet = typeof WeakSet === 'function';
|
11 | this._inner = this._hasWeakSet ? new WeakSet() : [];
|
12 | }
|
13 | /**
|
14 | * Sets obj to remember.
|
15 | * @param obj Object to remember
|
16 | */
|
17 | Memo.prototype.memoize = function (obj) {
|
18 | if (this._hasWeakSet) {
|
19 | if (this._inner.has(obj)) {
|
20 | return true;
|
21 | }
|
22 | this._inner.add(obj);
|
23 | return false;
|
24 | }
|
25 | // eslint-disable-next-line @typescript-eslint/prefer-for-of
|
26 | for (var i = 0; i < this._inner.length; i++) {
|
27 | var value = this._inner[i];
|
28 | if (value === obj) {
|
29 | return true;
|
30 | }
|
31 | }
|
32 | this._inner.push(obj);
|
33 | return false;
|
34 | };
|
35 | /**
|
36 | * Removes object from internal storage.
|
37 | * @param obj Object to forget
|
38 | */
|
39 | Memo.prototype.unmemoize = function (obj) {
|
40 | if (this._hasWeakSet) {
|
41 | this._inner.delete(obj);
|
42 | }
|
43 | else {
|
44 | for (var i = 0; i < this._inner.length; i++) {
|
45 | if (this._inner[i] === obj) {
|
46 | this._inner.splice(i, 1);
|
47 | break;
|
48 | }
|
49 | }
|
50 | }
|
51 | };
|
52 | return Memo;
|
53 | }());
|
54 | exports.Memo = Memo;
|
55 | //# sourceMappingURL=memo.js.map |
\ | No newline at end of file |