@signaltree/core 4.2.0 → 4.2.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.
|
@@ -14,9 +14,6 @@ function resolveNestedSignal(tree, path) {
|
|
|
14
14
|
let current = tree.state;
|
|
15
15
|
for (let i = 0; i < segments.length; i++) {
|
|
16
16
|
const segment = segments[i];
|
|
17
|
-
if (isAnySignal(current)) {
|
|
18
|
-
current = current();
|
|
19
|
-
}
|
|
20
17
|
current = current[segment];
|
|
21
18
|
if (current === undefined) {
|
|
22
19
|
const attemptedPath = segments.slice(0, i + 1).join('.');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { computed } from '@angular/core';
|
|
1
2
|
import { isNodeAccessor } from '../../../lib/utils.js';
|
|
2
3
|
import { LRUCache } from '../../../lru-cache.js';
|
|
3
4
|
import { deepEqual } from '../../../deep-equal.js';
|
|
@@ -281,6 +282,25 @@ function withMemoization(config = {}) {
|
|
|
281
282
|
});
|
|
282
283
|
applyUpdateResult(result);
|
|
283
284
|
};
|
|
285
|
+
const memoizeResultCache = createMemoCacheStore(MAX_CACHE_SIZE, true);
|
|
286
|
+
tree.memoize = (fn, cacheKey) => {
|
|
287
|
+
return computed(() => {
|
|
288
|
+
const currentState = originalTreeCall();
|
|
289
|
+
const key = cacheKey || generateCacheKey(fn, [currentState]);
|
|
290
|
+
const cached = memoizeResultCache.get(key);
|
|
291
|
+
if (cached && equalityFn(cached.deps, [currentState])) {
|
|
292
|
+
return cached.value;
|
|
293
|
+
}
|
|
294
|
+
const result = fn(currentState);
|
|
295
|
+
memoizeResultCache.set(key, {
|
|
296
|
+
value: result,
|
|
297
|
+
deps: [currentState],
|
|
298
|
+
timestamp: Date.now(),
|
|
299
|
+
hitCount: 1
|
|
300
|
+
});
|
|
301
|
+
return result;
|
|
302
|
+
});
|
|
303
|
+
};
|
|
284
304
|
tree.clearMemoCache = key => {
|
|
285
305
|
if (key) {
|
|
286
306
|
cache.delete(key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signaltree/core",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Lightweight, type-safe signal-based state management for Angular. Core package providing hierarchical signal trees, basic entity management, and async actions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -7,16 +7,16 @@ interface EntityConfig {
|
|
|
7
7
|
export declare function withEntities(config?: EntityConfig): <T>(tree: SignalTree<T>) => SignalTree<T> & {
|
|
8
8
|
entities<E extends {
|
|
9
9
|
id: string | number;
|
|
10
|
-
}>(entityKey: keyof T): EntityHelpers<E>;
|
|
10
|
+
}>(entityKey: keyof T | string): EntityHelpers<E>;
|
|
11
11
|
};
|
|
12
12
|
export declare function enableEntities(): <T>(tree: SignalTree<T>) => SignalTree<T> & {
|
|
13
13
|
entities<E extends {
|
|
14
14
|
id: string | number;
|
|
15
|
-
}>(entityKey: keyof T): EntityHelpers<E>;
|
|
15
|
+
}>(entityKey: keyof T | string): EntityHelpers<E>;
|
|
16
16
|
};
|
|
17
17
|
export declare function withHighPerformanceEntities(): <T>(tree: SignalTree<T>) => SignalTree<T> & {
|
|
18
18
|
entities<E extends {
|
|
19
19
|
id: string | number;
|
|
20
|
-
}>(entityKey: keyof T): EntityHelpers<E>;
|
|
20
|
+
}>(entityKey: keyof T | string): EntityHelpers<E>;
|
|
21
21
|
};
|
|
22
22
|
export {};
|