@signaltree/core 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -76
- package/dist/constants.js +6 -0
- package/dist/deep-equal.js +41 -0
- package/dist/enhancers/batching/batching.js +189 -0
- package/dist/enhancers/devtools/devtools.js +306 -0
- package/dist/enhancers/effects/effects.js +66 -0
- package/dist/enhancers/entities/entities.js +51 -0
- package/dist/enhancers/index.js +72 -0
- package/dist/enhancers/memoization/memoization.js +420 -0
- package/dist/enhancers/presets/lib/presets.js +27 -0
- package/dist/enhancers/serialization/constants.js +15 -0
- package/dist/enhancers/serialization/serialization.js +656 -0
- package/dist/enhancers/time-travel/time-travel.js +231 -0
- package/dist/enhancers/time-travel/utils.js +11 -0
- package/dist/index.js +19 -0
- package/dist/is-built-in-object.js +23 -0
- package/dist/lib/async-helpers.js +77 -0
- package/dist/lib/constants.js +56 -0
- package/dist/lib/entity-signal.js +283 -0
- package/dist/lib/memory/memory-manager.js +164 -0
- package/dist/lib/path-notifier.js +106 -0
- package/dist/lib/presets.js +21 -0
- package/dist/lib/security/security-validator.js +121 -0
- package/dist/lib/signal-tree.js +277 -0
- package/dist/lib/types.js +9 -0
- package/dist/lib/utils.js +299 -0
- package/dist/lru-cache.js +64 -0
- package/dist/parse-path.js +13 -0
- package/package.json +1 -1
- package/src/enhancers/batching/batching.d.ts +11 -0
- package/src/enhancers/batching/batching.types.d.ts +1 -0
- package/src/enhancers/batching/index.d.ts +1 -0
- package/src/enhancers/batching/test-setup.d.ts +3 -0
- package/src/enhancers/devtools/devtools.d.ts +68 -0
- package/src/enhancers/devtools/devtools.types.d.ts +1 -0
- package/src/enhancers/devtools/index.d.ts +1 -0
- package/src/enhancers/devtools/test-setup.d.ts +3 -0
- package/src/enhancers/effects/effects.d.ts +9 -0
- package/src/enhancers/effects/effects.types.d.ts +1 -0
- package/src/enhancers/effects/index.d.ts +1 -0
- package/src/enhancers/entities/entities.d.ts +11 -0
- package/src/enhancers/entities/entities.types.d.ts +1 -0
- package/src/enhancers/entities/index.d.ts +1 -0
- package/src/enhancers/entities/test-setup.d.ts +3 -0
- package/src/enhancers/index.d.ts +3 -0
- package/src/enhancers/memoization/index.d.ts +1 -0
- package/src/enhancers/memoization/memoization.d.ts +54 -0
- package/src/enhancers/memoization/memoization.types.d.ts +1 -0
- package/src/enhancers/memoization/test-setup.d.ts +3 -0
- package/src/enhancers/presets/index.d.ts +1 -0
- package/src/enhancers/presets/lib/presets.d.ts +8 -0
- package/src/enhancers/serialization/constants.d.ts +14 -0
- package/src/enhancers/serialization/index.d.ts +2 -0
- package/src/enhancers/serialization/serialization.d.ts +68 -0
- package/src/enhancers/serialization/test-setup.d.ts +3 -0
- package/src/enhancers/test-helpers/types-equals.d.ts +2 -0
- package/src/enhancers/time-travel/index.d.ts +1 -0
- package/src/enhancers/time-travel/test-setup.d.ts +3 -0
- package/src/enhancers/time-travel/time-travel.d.ts +10 -0
- package/src/enhancers/time-travel/time-travel.types.d.ts +1 -0
- package/src/enhancers/time-travel/utils.d.ts +2 -0
- package/src/enhancers/types.d.ts +1 -0
- package/src/enhancers/typing/helpers-types.d.ts +2 -0
- package/src/index.d.ts +17 -0
- package/src/lib/async-helpers.d.ts +8 -0
- package/src/lib/constants.d.ts +41 -0
- package/src/lib/dev-proxy.d.ts +3 -0
- package/src/lib/entity-signal.d.ts +1 -0
- package/src/lib/memory/memory-manager.d.ts +30 -0
- package/src/lib/path-notifier.d.ts +4 -0
- package/src/lib/performance/diff-engine.d.ts +33 -0
- package/src/lib/performance/path-index.d.ts +25 -0
- package/src/lib/performance/update-engine.d.ts +32 -0
- package/src/lib/presets.d.ts +34 -0
- package/src/lib/security/security-validator.d.ts +33 -0
- package/src/lib/signal-tree.d.ts +3 -0
- package/src/lib/types.d.ts +301 -0
- package/src/lib/utils.d.ts +32 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { computed } from '@angular/core';
|
|
2
|
+
import { isNodeAccessor } from '../../lib/utils.js';
|
|
3
|
+
import { deepEqual } from '../../deep-equal.js';
|
|
4
|
+
import { LRUCache } from '../../lru-cache.js';
|
|
5
|
+
|
|
6
|
+
function isDevMode() {
|
|
7
|
+
if (typeof __DEV__ !== 'undefined') {
|
|
8
|
+
return __DEV__;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const MAX_CACHE_SIZE = 1000;
|
|
13
|
+
const DEFAULT_TTL = 5 * 60 * 1000;
|
|
14
|
+
const memoizationCache = new Map();
|
|
15
|
+
function createMemoCacheStore(maxSize, enableLRU) {
|
|
16
|
+
if (enableLRU) {
|
|
17
|
+
const cache = new LRUCache(maxSize);
|
|
18
|
+
const shadow = new Map();
|
|
19
|
+
const pruneShadow = () => {
|
|
20
|
+
while (shadow.size > cache.size()) {
|
|
21
|
+
const oldestKey = shadow.keys().next().value;
|
|
22
|
+
if (oldestKey === undefined) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
shadow.delete(oldestKey);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
get: key => {
|
|
30
|
+
const value = cache.get(key);
|
|
31
|
+
if (value !== undefined) {
|
|
32
|
+
shadow.set(key, value);
|
|
33
|
+
} else if (shadow.has(key)) {
|
|
34
|
+
shadow.delete(key);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
},
|
|
38
|
+
set: (key, value) => {
|
|
39
|
+
cache.set(key, value);
|
|
40
|
+
shadow.set(key, value);
|
|
41
|
+
pruneShadow();
|
|
42
|
+
},
|
|
43
|
+
delete: key => {
|
|
44
|
+
cache.delete(key);
|
|
45
|
+
shadow.delete(key);
|
|
46
|
+
},
|
|
47
|
+
clear: () => {
|
|
48
|
+
cache.clear();
|
|
49
|
+
shadow.clear();
|
|
50
|
+
},
|
|
51
|
+
size: () => shadow.size,
|
|
52
|
+
forEach: callback => {
|
|
53
|
+
shadow.forEach((value, key) => callback(value, key));
|
|
54
|
+
},
|
|
55
|
+
keys: () => shadow.keys()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const store = new Map();
|
|
59
|
+
return {
|
|
60
|
+
get: key => store.get(key),
|
|
61
|
+
set: (key, value) => {
|
|
62
|
+
store.set(key, value);
|
|
63
|
+
},
|
|
64
|
+
delete: key => store.delete(key),
|
|
65
|
+
clear: () => store.clear(),
|
|
66
|
+
size: () => store.size,
|
|
67
|
+
forEach: callback => {
|
|
68
|
+
store.forEach((value, key) => callback(value, key));
|
|
69
|
+
},
|
|
70
|
+
keys: () => store.keys()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function getCleanupInterval(tree) {
|
|
74
|
+
return tree._memoCleanupInterval;
|
|
75
|
+
}
|
|
76
|
+
function setCleanupInterval(tree, interval) {
|
|
77
|
+
if (interval === undefined) {
|
|
78
|
+
delete tree._memoCleanupInterval;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
tree._memoCleanupInterval = interval;
|
|
82
|
+
}
|
|
83
|
+
function clearCleanupInterval(tree) {
|
|
84
|
+
const interval = getCleanupInterval(tree);
|
|
85
|
+
if (!interval) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
clearInterval(interval);
|
|
90
|
+
} catch {}
|
|
91
|
+
setCleanupInterval(tree);
|
|
92
|
+
}
|
|
93
|
+
function resetMemoizationCaches() {
|
|
94
|
+
memoizationCache.forEach((cache, tree) => {
|
|
95
|
+
cache.clear();
|
|
96
|
+
clearCleanupInterval(tree);
|
|
97
|
+
});
|
|
98
|
+
memoizationCache.clear();
|
|
99
|
+
}
|
|
100
|
+
function shallowEqual(a, b) {
|
|
101
|
+
if (a === b) return true;
|
|
102
|
+
if (a == null || b == null) return false;
|
|
103
|
+
if (typeof a !== typeof b) return false;
|
|
104
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
105
|
+
const objA = a;
|
|
106
|
+
const objB = b;
|
|
107
|
+
let countA = 0;
|
|
108
|
+
for (const key in objA) {
|
|
109
|
+
if (!Object.prototype.hasOwnProperty.call(objA, key)) continue;
|
|
110
|
+
countA++;
|
|
111
|
+
if (!(key in objB) || objA[key] !== objB[key]) return false;
|
|
112
|
+
}
|
|
113
|
+
let countB = 0;
|
|
114
|
+
for (const key in objB) {
|
|
115
|
+
if (Object.prototype.hasOwnProperty.call(objB, key)) countB++;
|
|
116
|
+
}
|
|
117
|
+
return countA === countB;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function generateCacheKey(fn, args) {
|
|
122
|
+
try {
|
|
123
|
+
return `${fn.name || 'anonymous'}_${JSON.stringify(args)}`;
|
|
124
|
+
} catch {
|
|
125
|
+
return `${fn.name || 'anonymous'}_${args.length}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function getEqualityFn(strategy) {
|
|
129
|
+
switch (strategy) {
|
|
130
|
+
case 'shallow':
|
|
131
|
+
return shallowEqual;
|
|
132
|
+
case 'reference':
|
|
133
|
+
return (a, b) => a === b;
|
|
134
|
+
case 'deep':
|
|
135
|
+
default:
|
|
136
|
+
return deepEqual;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function memoize(fn, keyFn, config = {}) {
|
|
140
|
+
const maxSize = config.maxCacheSize ?? MAX_CACHE_SIZE;
|
|
141
|
+
const ttl = config.ttl ?? DEFAULT_TTL;
|
|
142
|
+
const equality = getEqualityFn(config.equality ?? 'shallow');
|
|
143
|
+
const enableLRU = config.enableLRU ?? false;
|
|
144
|
+
const cache = createMemoCacheStore(maxSize, enableLRU);
|
|
145
|
+
const cleanExpiredEntries = () => {
|
|
146
|
+
if (!ttl) return;
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
cache.forEach((entry, key) => {
|
|
149
|
+
if (entry.timestamp && now - entry.timestamp > ttl) {
|
|
150
|
+
cache.delete(key);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
return (...args) => {
|
|
155
|
+
if (ttl && Math.random() < 0.01) {
|
|
156
|
+
cleanExpiredEntries();
|
|
157
|
+
}
|
|
158
|
+
const key = keyFn ? keyFn(...args) : generateCacheKey(fn, args);
|
|
159
|
+
const cached = cache.get(key);
|
|
160
|
+
if (cached && (keyFn || equality(cached.deps, args))) {
|
|
161
|
+
if (enableLRU) {
|
|
162
|
+
cached.hitCount += 1;
|
|
163
|
+
}
|
|
164
|
+
return cached.value;
|
|
165
|
+
}
|
|
166
|
+
const result = fn(...args);
|
|
167
|
+
cache.set(key, {
|
|
168
|
+
value: result,
|
|
169
|
+
deps: args,
|
|
170
|
+
timestamp: Date.now(),
|
|
171
|
+
hitCount: 1
|
|
172
|
+
});
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function memoizeShallow(fn, keyFn) {
|
|
177
|
+
return memoize(fn, keyFn, {
|
|
178
|
+
equality: 'shallow',
|
|
179
|
+
enableLRU: false,
|
|
180
|
+
ttl: undefined,
|
|
181
|
+
maxCacheSize: 100
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function memoizeReference(fn, keyFn) {
|
|
185
|
+
return memoize(fn, keyFn, {
|
|
186
|
+
equality: 'reference',
|
|
187
|
+
enableLRU: false,
|
|
188
|
+
ttl: undefined,
|
|
189
|
+
maxCacheSize: 50
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const MEMOIZATION_PRESETS = {
|
|
193
|
+
selector: {
|
|
194
|
+
equality: 'reference',
|
|
195
|
+
maxCacheSize: 10,
|
|
196
|
+
enableLRU: false,
|
|
197
|
+
ttl: undefined
|
|
198
|
+
},
|
|
199
|
+
computed: {
|
|
200
|
+
equality: 'shallow',
|
|
201
|
+
maxCacheSize: 100,
|
|
202
|
+
enableLRU: false,
|
|
203
|
+
ttl: undefined
|
|
204
|
+
},
|
|
205
|
+
deepState: {
|
|
206
|
+
equality: 'deep',
|
|
207
|
+
maxCacheSize: 1000,
|
|
208
|
+
enableLRU: true,
|
|
209
|
+
ttl: 5 * 60 * 1000
|
|
210
|
+
},
|
|
211
|
+
highFrequency: {
|
|
212
|
+
equality: 'reference',
|
|
213
|
+
maxCacheSize: 5,
|
|
214
|
+
enableLRU: false,
|
|
215
|
+
ttl: undefined
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
function selectorMemoization() {
|
|
219
|
+
return memoization(MEMOIZATION_PRESETS.selector);
|
|
220
|
+
}
|
|
221
|
+
function computedMemoization() {
|
|
222
|
+
return memoization(MEMOIZATION_PRESETS.computed);
|
|
223
|
+
}
|
|
224
|
+
function deepStateMemoization() {
|
|
225
|
+
return memoization(MEMOIZATION_PRESETS.deepState);
|
|
226
|
+
}
|
|
227
|
+
function highFrequencyMemoization() {
|
|
228
|
+
return memoization(MEMOIZATION_PRESETS.highFrequency);
|
|
229
|
+
}
|
|
230
|
+
Object.assign((config = {}) => memoization(config), {
|
|
231
|
+
selector: selectorMemoization,
|
|
232
|
+
computed: computedMemoization,
|
|
233
|
+
deep: deepStateMemoization,
|
|
234
|
+
fast: highFrequencyMemoization
|
|
235
|
+
});
|
|
236
|
+
function memoization(config = {}) {
|
|
237
|
+
const {
|
|
238
|
+
enabled = true,
|
|
239
|
+
maxCacheSize = 1000,
|
|
240
|
+
ttl,
|
|
241
|
+
equality = 'deep',
|
|
242
|
+
enableLRU = true
|
|
243
|
+
} = config;
|
|
244
|
+
const enhancer = tree => {
|
|
245
|
+
const originalTreeCall = tree.bind(tree);
|
|
246
|
+
const applyUpdateResult = result => {
|
|
247
|
+
Object.entries(result).forEach(([propKey, value]) => {
|
|
248
|
+
const property = tree.state[propKey];
|
|
249
|
+
if (property && 'set' in property) {
|
|
250
|
+
property.set(value);
|
|
251
|
+
} else if (isNodeAccessor(property)) {
|
|
252
|
+
property(value);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
if (!enabled) {
|
|
257
|
+
const memoTree = tree;
|
|
258
|
+
memoTree.memoize = (fn, _cacheKey) => {
|
|
259
|
+
return computed(() => fn(originalTreeCall()));
|
|
260
|
+
};
|
|
261
|
+
memoTree.memoizedUpdate = updater => {
|
|
262
|
+
const currentState = originalTreeCall();
|
|
263
|
+
const result = updater(currentState);
|
|
264
|
+
applyUpdateResult(result);
|
|
265
|
+
};
|
|
266
|
+
memoTree.clearMemoCache = () => {};
|
|
267
|
+
memoTree.clearCache = memoTree.clearMemoCache;
|
|
268
|
+
memoTree.getCacheStats = () => ({
|
|
269
|
+
size: 0,
|
|
270
|
+
hitRate: 0,
|
|
271
|
+
totalHits: 0,
|
|
272
|
+
totalMisses: 0,
|
|
273
|
+
keys: []
|
|
274
|
+
});
|
|
275
|
+
return memoTree;
|
|
276
|
+
}
|
|
277
|
+
const cache = createMemoCacheStore(maxCacheSize, enableLRU);
|
|
278
|
+
memoizationCache.set(tree, cache);
|
|
279
|
+
const equalityFn = getEqualityFn(equality);
|
|
280
|
+
tree.memoizedUpdate = (updater, cacheKey) => {
|
|
281
|
+
const currentState = originalTreeCall();
|
|
282
|
+
const key = cacheKey || generateCacheKey(updater, [currentState]);
|
|
283
|
+
const cached = cache.get(key);
|
|
284
|
+
if (cached && equalityFn(cached.deps, [currentState])) {
|
|
285
|
+
const cachedUpdate = cached.value;
|
|
286
|
+
applyUpdateResult(cachedUpdate);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const result = updater(currentState);
|
|
290
|
+
cache.set(key, {
|
|
291
|
+
value: result,
|
|
292
|
+
deps: [currentState],
|
|
293
|
+
timestamp: Date.now(),
|
|
294
|
+
hitCount: 1
|
|
295
|
+
});
|
|
296
|
+
applyUpdateResult(result);
|
|
297
|
+
};
|
|
298
|
+
const memoizeResultCache = createMemoCacheStore(MAX_CACHE_SIZE, true);
|
|
299
|
+
tree.memoize = (fn, cacheKey) => {
|
|
300
|
+
return computed(() => {
|
|
301
|
+
const currentState = originalTreeCall();
|
|
302
|
+
const key = cacheKey || generateCacheKey(fn, [currentState]);
|
|
303
|
+
const cached = memoizeResultCache.get(key);
|
|
304
|
+
if (cached && equalityFn(cached.deps, [currentState])) {
|
|
305
|
+
return cached.value;
|
|
306
|
+
}
|
|
307
|
+
if (isDevMode() && tree.__devHooks?.onRecompute) {
|
|
308
|
+
try {
|
|
309
|
+
tree.__devHooks.onRecompute(key, 1);
|
|
310
|
+
} catch {}
|
|
311
|
+
}
|
|
312
|
+
const result = fn(currentState);
|
|
313
|
+
memoizeResultCache.set(key, {
|
|
314
|
+
value: result,
|
|
315
|
+
deps: [currentState],
|
|
316
|
+
timestamp: Date.now(),
|
|
317
|
+
hitCount: 1
|
|
318
|
+
});
|
|
319
|
+
return result;
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
tree.clearMemoCache = key => {
|
|
323
|
+
if (key) {
|
|
324
|
+
cache.delete(key);
|
|
325
|
+
} else {
|
|
326
|
+
cache.clear();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
tree.clearCache = tree.clearMemoCache;
|
|
330
|
+
tree.getCacheStats = () => {
|
|
331
|
+
let totalHits = 0;
|
|
332
|
+
let totalMisses = 0;
|
|
333
|
+
cache.forEach(entry => {
|
|
334
|
+
totalHits += entry.hitCount || 0;
|
|
335
|
+
totalMisses += Math.floor((entry.hitCount || 0) / 2);
|
|
336
|
+
});
|
|
337
|
+
const hitRate = totalHits + totalMisses > 0 ? totalHits / (totalHits + totalMisses) : 0;
|
|
338
|
+
return {
|
|
339
|
+
size: cache.size(),
|
|
340
|
+
hitRate,
|
|
341
|
+
totalHits,
|
|
342
|
+
totalMisses,
|
|
343
|
+
keys: Array.from(cache.keys())
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
const maybeInterval = getCleanupInterval(tree);
|
|
347
|
+
if (maybeInterval) {
|
|
348
|
+
const origClear = tree.clearMemoCache.bind(tree);
|
|
349
|
+
tree.clearMemoCache = key => {
|
|
350
|
+
origClear(key);
|
|
351
|
+
clearCleanupInterval(tree);
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
tree.clearCache = tree.clearMemoCache;
|
|
355
|
+
if (ttl) {
|
|
356
|
+
const cleanup = () => {
|
|
357
|
+
const now = Date.now();
|
|
358
|
+
cache.forEach((entry, key) => {
|
|
359
|
+
if (entry.timestamp && now - entry.timestamp > ttl) {
|
|
360
|
+
cache.delete(key);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const intervalId = setInterval(cleanup, ttl);
|
|
365
|
+
setCleanupInterval(tree, intervalId);
|
|
366
|
+
}
|
|
367
|
+
return tree;
|
|
368
|
+
};
|
|
369
|
+
return enhancer;
|
|
370
|
+
}
|
|
371
|
+
function highPerformanceMemoization() {
|
|
372
|
+
return memoization({
|
|
373
|
+
enabled: true,
|
|
374
|
+
maxCacheSize: 10000,
|
|
375
|
+
ttl: 300000,
|
|
376
|
+
equality: 'shallow',
|
|
377
|
+
enableLRU: true
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function lightweightMemoization() {
|
|
381
|
+
return memoization({
|
|
382
|
+
enabled: true,
|
|
383
|
+
maxCacheSize: 100,
|
|
384
|
+
ttl: undefined,
|
|
385
|
+
equality: 'reference',
|
|
386
|
+
enableLRU: false
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
function shallowMemoization() {
|
|
390
|
+
return memoization({
|
|
391
|
+
enabled: true,
|
|
392
|
+
maxCacheSize: 1000,
|
|
393
|
+
ttl: 60000,
|
|
394
|
+
equality: 'shallow',
|
|
395
|
+
enableLRU: true
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
function clearAllCaches() {
|
|
399
|
+
resetMemoizationCaches();
|
|
400
|
+
}
|
|
401
|
+
function getGlobalCacheStats() {
|
|
402
|
+
let totalSize = 0;
|
|
403
|
+
let totalHits = 0;
|
|
404
|
+
let treeCount = 0;
|
|
405
|
+
memoizationCache.forEach(cache => {
|
|
406
|
+
treeCount++;
|
|
407
|
+
totalSize += cache.size();
|
|
408
|
+
cache.forEach(entry => {
|
|
409
|
+
totalHits += entry.hitCount || 0;
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
return {
|
|
413
|
+
treeCount,
|
|
414
|
+
totalSize,
|
|
415
|
+
totalHits,
|
|
416
|
+
averageCacheSize: treeCount > 0 ? totalSize / treeCount : 0
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { MEMOIZATION_PRESETS, clearAllCaches, computedMemoization, deepStateMemoization, getGlobalCacheStats, highFrequencyMemoization, highPerformanceMemoization, lightweightMemoization, memoization, memoize, memoizeReference, memoizeShallow, selectorMemoization, shallowMemoization };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const TREE_PRESETS = {};
|
|
2
|
+
function createPresetConfig(preset, overrides = {}) {
|
|
3
|
+
return {
|
|
4
|
+
...overrides
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
function validatePreset(preset) {
|
|
8
|
+
return typeof preset === 'string';
|
|
9
|
+
}
|
|
10
|
+
function getAvailablePresets() {
|
|
11
|
+
return Object.keys(TREE_PRESETS);
|
|
12
|
+
}
|
|
13
|
+
function combinePresets(presets, overrides = {}) {
|
|
14
|
+
let combined = {};
|
|
15
|
+
for (const p of presets) {
|
|
16
|
+
combined = {
|
|
17
|
+
...combined,
|
|
18
|
+
...TREE_PRESETS[p]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...combined,
|
|
23
|
+
...overrides
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { TREE_PRESETS, combinePresets, createPresetConfig, getAvailablePresets, validatePreset };
|