@signaltree/core 6.2.0 → 6.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.
- package/LICENSE +54 -0
- package/package.json +2 -2
- package/dist/constants.js +0 -6
- package/dist/deep-equal.js +0 -41
- package/dist/enhancers/batching/batching.js +0 -219
- package/dist/enhancers/devtools/devtools.js +0 -306
- package/dist/enhancers/effects/effects.js +0 -66
- package/dist/enhancers/entities/entities.js +0 -51
- package/dist/enhancers/index.js +0 -72
- package/dist/enhancers/memoization/memoization.js +0 -420
- package/dist/enhancers/presets/lib/presets.js +0 -27
- package/dist/enhancers/serialization/constants.js +0 -15
- package/dist/enhancers/serialization/serialization.js +0 -656
- package/dist/enhancers/time-travel/time-travel.js +0 -231
- package/dist/enhancers/time-travel/utils.js +0 -11
- package/dist/enhancers/utils/copy-tree-properties.js +0 -20
- package/dist/index.js +0 -20
- package/dist/is-built-in-object.js +0 -23
- package/dist/lib/async-helpers.js +0 -77
- package/dist/lib/constants.js +0 -56
- package/dist/lib/edit-session.js +0 -84
- package/dist/lib/entity-signal.js +0 -283
- package/dist/lib/memory/memory-manager.js +0 -164
- package/dist/lib/path-notifier.js +0 -106
- package/dist/lib/presets.js +0 -21
- package/dist/lib/security/security-validator.js +0 -121
- package/dist/lib/signal-tree.js +0 -277
- package/dist/lib/types.js +0 -9
- package/dist/lib/utils.js +0 -264
- package/dist/lru-cache.js +0 -64
- package/dist/parse-path.js +0 -13
- package/src/enhancers/batching/batching.d.ts +0 -10
- package/src/enhancers/batching/batching.types.d.ts +0 -1
- package/src/enhancers/batching/index.d.ts +0 -1
- package/src/enhancers/batching/test-setup.d.ts +0 -3
- package/src/enhancers/devtools/devtools.d.ts +0 -68
- package/src/enhancers/devtools/devtools.types.d.ts +0 -1
- package/src/enhancers/devtools/index.d.ts +0 -1
- package/src/enhancers/devtools/test-setup.d.ts +0 -3
- package/src/enhancers/effects/effects.d.ts +0 -9
- package/src/enhancers/effects/effects.types.d.ts +0 -1
- package/src/enhancers/effects/index.d.ts +0 -1
- package/src/enhancers/entities/entities.d.ts +0 -11
- package/src/enhancers/entities/entities.types.d.ts +0 -1
- package/src/enhancers/entities/index.d.ts +0 -1
- package/src/enhancers/entities/test-setup.d.ts +0 -3
- package/src/enhancers/index.d.ts +0 -3
- package/src/enhancers/memoization/index.d.ts +0 -1
- package/src/enhancers/memoization/memoization.d.ts +0 -54
- package/src/enhancers/memoization/memoization.types.d.ts +0 -1
- package/src/enhancers/memoization/test-setup.d.ts +0 -3
- package/src/enhancers/presets/index.d.ts +0 -1
- package/src/enhancers/presets/lib/presets.d.ts +0 -8
- package/src/enhancers/serialization/constants.d.ts +0 -14
- package/src/enhancers/serialization/index.d.ts +0 -2
- package/src/enhancers/serialization/serialization.d.ts +0 -68
- package/src/enhancers/serialization/test-setup.d.ts +0 -3
- package/src/enhancers/test-helpers/types-equals.d.ts +0 -2
- package/src/enhancers/time-travel/index.d.ts +0 -1
- package/src/enhancers/time-travel/test-setup.d.ts +0 -3
- package/src/enhancers/time-travel/time-travel.d.ts +0 -10
- package/src/enhancers/time-travel/time-travel.types.d.ts +0 -1
- package/src/enhancers/time-travel/utils.d.ts +0 -2
- package/src/enhancers/types.d.ts +0 -1
- package/src/enhancers/typing/helpers-types.d.ts +0 -2
- package/src/enhancers/utils/copy-tree-properties.d.ts +0 -1
- package/src/index.d.ts +0 -19
- package/src/lib/async-helpers.d.ts +0 -8
- package/src/lib/constants.d.ts +0 -41
- package/src/lib/dev-proxy.d.ts +0 -3
- package/src/lib/edit-session.d.ts +0 -21
- package/src/lib/entity-signal.d.ts +0 -1
- package/src/lib/memory/memory-manager.d.ts +0 -30
- package/src/lib/path-notifier.d.ts +0 -4
- package/src/lib/performance/diff-engine.d.ts +0 -33
- package/src/lib/performance/path-index.d.ts +0 -25
- package/src/lib/performance/update-engine.d.ts +0 -32
- package/src/lib/presets.d.ts +0 -34
- package/src/lib/security/security-validator.d.ts +0 -33
- package/src/lib/signal-tree.d.ts +0 -3
- package/src/lib/types.d.ts +0 -301
- package/src/lib/utils.d.ts +0 -32
package/dist/lib/signal-tree.js
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { signal, isSignal } from '@angular/core';
|
|
2
|
-
import { SIGNAL_TREE_MESSAGES, SIGNAL_TREE_CONSTANTS } from './constants.js';
|
|
3
|
-
import { SignalMemoryManager } from './memory/memory-manager.js';
|
|
4
|
-
import { SecurityValidator } from './security/security-validator.js';
|
|
5
|
-
import { createLazySignalTree, unwrap } from './utils.js';
|
|
6
|
-
import { deepEqual } from '../deep-equal.js';
|
|
7
|
-
import { isBuiltInObject } from '../is-built-in-object.js';
|
|
8
|
-
|
|
9
|
-
const NODE_ACCESSOR_SYMBOL = Symbol.for('SignalTree:NodeAccessor');
|
|
10
|
-
function isNodeAccessor(value) {
|
|
11
|
-
return typeof value === 'function' && value[NODE_ACCESSOR_SYMBOL] === true;
|
|
12
|
-
}
|
|
13
|
-
function isEntityMapMarker(value) {
|
|
14
|
-
return Boolean(value && typeof value === 'object' && value['__isEntityMap'] === true);
|
|
15
|
-
}
|
|
16
|
-
function createEqualityFn(useShallowComparison) {
|
|
17
|
-
return useShallowComparison ? Object.is : deepEqual;
|
|
18
|
-
}
|
|
19
|
-
function estimateObjectSize(obj, maxDepth = SIGNAL_TREE_CONSTANTS.ESTIMATE_MAX_DEPTH, currentDepth = 0) {
|
|
20
|
-
if (currentDepth >= maxDepth) return 1;
|
|
21
|
-
if (obj === null || obj === undefined) return 0;
|
|
22
|
-
if (typeof obj !== 'object') return 1;
|
|
23
|
-
let size = 0;
|
|
24
|
-
try {
|
|
25
|
-
if (Array.isArray(obj)) {
|
|
26
|
-
size = obj.length;
|
|
27
|
-
const sampleSize = Math.min(SIGNAL_TREE_CONSTANTS.ESTIMATE_SAMPLE_SIZE_ARRAY, obj.length);
|
|
28
|
-
for (let i = 0; i < sampleSize; i++) {
|
|
29
|
-
size += estimateObjectSize(obj[i], maxDepth, currentDepth + 1) * 0.1;
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
const keys = Object.keys(obj);
|
|
33
|
-
size = keys.length;
|
|
34
|
-
const sampleSize = Math.min(SIGNAL_TREE_CONSTANTS.ESTIMATE_SAMPLE_SIZE_OBJECT, keys.length);
|
|
35
|
-
for (let i = 0; i < sampleSize; i++) {
|
|
36
|
-
const value = obj[keys[i]];
|
|
37
|
-
size += estimateObjectSize(value, maxDepth, currentDepth + 1) * 0.5;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
} catch {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
return Math.floor(size);
|
|
44
|
-
}
|
|
45
|
-
function shouldUseLazy(obj, config, precomputedSize) {
|
|
46
|
-
if (config.useLazySignals !== undefined) return config.useLazySignals;
|
|
47
|
-
if (config.debugMode || config.enableDevTools) return false;
|
|
48
|
-
const estimatedSize = precomputedSize ?? estimateObjectSize(obj);
|
|
49
|
-
return estimatedSize > SIGNAL_TREE_CONSTANTS.LAZY_THRESHOLD;
|
|
50
|
-
}
|
|
51
|
-
function validateTree(obj, config) {
|
|
52
|
-
if (!config.security) return;
|
|
53
|
-
const validator = new SecurityValidator(config.security);
|
|
54
|
-
function validate(value, path) {
|
|
55
|
-
if (value === null || value === undefined) return;
|
|
56
|
-
if (typeof value !== 'object') {
|
|
57
|
-
validator.validateValue(value);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (isBuiltInObject(value)) return;
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
value.forEach((item, i) => validate(item, [...path, String(i)]));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
for (const key of Object.keys(value)) {
|
|
66
|
-
try {
|
|
67
|
-
validator.validateKey(key);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
throw new Error(`${error.message}\nPath: ${[...path, key].join('.')}`);
|
|
70
|
-
}
|
|
71
|
-
const val = value[key];
|
|
72
|
-
try {
|
|
73
|
-
validator.validateValue(val);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
throw new Error(`${error.message}\nPath: ${[...path, key].join('.')}`);
|
|
76
|
-
}
|
|
77
|
-
validate(val, [...path, key]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
validate(obj, []);
|
|
81
|
-
}
|
|
82
|
-
function makeNodeAccessor(store) {
|
|
83
|
-
const accessor = function (arg) {
|
|
84
|
-
if (arguments.length === 0) {
|
|
85
|
-
return unwrap(store);
|
|
86
|
-
}
|
|
87
|
-
if (typeof arg === 'function') {
|
|
88
|
-
const updater = arg;
|
|
89
|
-
const current = unwrap(store);
|
|
90
|
-
recursiveUpdate(store, updater(current));
|
|
91
|
-
} else {
|
|
92
|
-
recursiveUpdate(store, arg);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
accessor[NODE_ACCESSOR_SYMBOL] = true;
|
|
96
|
-
for (const key of Object.keys(store)) {
|
|
97
|
-
Object.defineProperty(accessor, key, {
|
|
98
|
-
value: store[key],
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return accessor;
|
|
104
|
-
}
|
|
105
|
-
function recursiveUpdate(target, updates) {
|
|
106
|
-
if (!updates || typeof updates !== 'object') return;
|
|
107
|
-
const targetObj = isNodeAccessor(target) ? target : target;
|
|
108
|
-
for (const [key, value] of Object.entries(updates)) {
|
|
109
|
-
const prop = targetObj[key];
|
|
110
|
-
if (prop === undefined) continue;
|
|
111
|
-
if (isSignal(prop) && 'set' in prop) {
|
|
112
|
-
prop.set(value);
|
|
113
|
-
} else if (isNodeAccessor(prop)) {
|
|
114
|
-
if (value && typeof value === 'object') {
|
|
115
|
-
recursiveUpdate(prop, value);
|
|
116
|
-
} else {
|
|
117
|
-
prop(value);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function createSignalStore(obj, equalityFn) {
|
|
123
|
-
if (obj === null || obj === undefined || typeof obj !== 'object') {
|
|
124
|
-
return signal(obj, {
|
|
125
|
-
equal: equalityFn
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (Array.isArray(obj)) {
|
|
129
|
-
return signal(obj, {
|
|
130
|
-
equal: equalityFn
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (isBuiltInObject(obj)) {
|
|
134
|
-
return signal(obj, {
|
|
135
|
-
equal: equalityFn
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const store = {};
|
|
139
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
140
|
-
if (isEntityMapMarker(value)) {
|
|
141
|
-
store[key] = value;
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
if (isSignal(value)) {
|
|
145
|
-
store[key] = value;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (value === null || value === undefined || typeof value !== 'object') {
|
|
149
|
-
store[key] = signal(value, {
|
|
150
|
-
equal: equalityFn
|
|
151
|
-
});
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (Array.isArray(value) || isBuiltInObject(value)) {
|
|
155
|
-
store[key] = signal(value, {
|
|
156
|
-
equal: equalityFn
|
|
157
|
-
});
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const nested = createSignalStore(value, equalityFn);
|
|
161
|
-
store[key] = makeNodeAccessor(nested);
|
|
162
|
-
}
|
|
163
|
-
return store;
|
|
164
|
-
}
|
|
165
|
-
function create(initialState, config) {
|
|
166
|
-
if (initialState === null || initialState === undefined) {
|
|
167
|
-
throw new Error(SIGNAL_TREE_MESSAGES.NULL_OR_UNDEFINED);
|
|
168
|
-
}
|
|
169
|
-
validateTree(initialState, config);
|
|
170
|
-
const equalityFn = createEqualityFn(config.useShallowComparison ?? false);
|
|
171
|
-
const estimatedSize = estimateObjectSize(initialState);
|
|
172
|
-
const useLazy = shouldUseLazy(initialState, config, estimatedSize);
|
|
173
|
-
let signalState;
|
|
174
|
-
let memoryManager;
|
|
175
|
-
if (useLazy && typeof initialState === 'object') {
|
|
176
|
-
try {
|
|
177
|
-
memoryManager = new SignalMemoryManager();
|
|
178
|
-
signalState = createLazySignalTree(initialState, equalityFn, '', memoryManager);
|
|
179
|
-
} catch (error) {
|
|
180
|
-
console.warn(SIGNAL_TREE_MESSAGES.LAZY_FALLBACK, error);
|
|
181
|
-
signalState = createSignalStore(initialState, equalityFn);
|
|
182
|
-
memoryManager = undefined;
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
signalState = createSignalStore(initialState, equalityFn);
|
|
186
|
-
}
|
|
187
|
-
const tree = function (arg) {
|
|
188
|
-
if (arguments.length === 0) {
|
|
189
|
-
return unwrap(signalState);
|
|
190
|
-
}
|
|
191
|
-
if (typeof arg === 'function') {
|
|
192
|
-
const updater = arg;
|
|
193
|
-
const current = unwrap(signalState);
|
|
194
|
-
recursiveUpdate(signalState, updater(current));
|
|
195
|
-
} else {
|
|
196
|
-
recursiveUpdate(signalState, arg);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
tree[NODE_ACCESSOR_SYMBOL] = true;
|
|
200
|
-
Object.defineProperty(tree, 'state', {
|
|
201
|
-
value: signalState,
|
|
202
|
-
enumerable: false,
|
|
203
|
-
writable: false
|
|
204
|
-
});
|
|
205
|
-
Object.defineProperty(tree, '$', {
|
|
206
|
-
value: signalState,
|
|
207
|
-
enumerable: false,
|
|
208
|
-
writable: false
|
|
209
|
-
});
|
|
210
|
-
Object.defineProperty(tree, 'with', {
|
|
211
|
-
value: function (enhancer) {
|
|
212
|
-
if (typeof enhancer !== 'function') {
|
|
213
|
-
throw new Error('Enhancer must be a function');
|
|
214
|
-
}
|
|
215
|
-
return enhancer(tree);
|
|
216
|
-
},
|
|
217
|
-
enumerable: false,
|
|
218
|
-
writable: false
|
|
219
|
-
});
|
|
220
|
-
Object.defineProperty(tree, 'bind', {
|
|
221
|
-
value: function (thisArg) {
|
|
222
|
-
return Function.prototype.bind.call(tree, thisArg);
|
|
223
|
-
},
|
|
224
|
-
enumerable: false,
|
|
225
|
-
writable: true,
|
|
226
|
-
configurable: true
|
|
227
|
-
});
|
|
228
|
-
Object.defineProperty(tree, 'destroy', {
|
|
229
|
-
value: function () {
|
|
230
|
-
if (memoryManager) {
|
|
231
|
-
memoryManager.dispose();
|
|
232
|
-
}
|
|
233
|
-
if (config.debugMode) {
|
|
234
|
-
console.log(SIGNAL_TREE_MESSAGES.TREE_DESTROYED);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
enumerable: false,
|
|
238
|
-
writable: true,
|
|
239
|
-
configurable: true
|
|
240
|
-
});
|
|
241
|
-
Object.defineProperty(tree, 'clearCache', {
|
|
242
|
-
value: () => {},
|
|
243
|
-
enumerable: false,
|
|
244
|
-
writable: true,
|
|
245
|
-
configurable: true
|
|
246
|
-
});
|
|
247
|
-
Object.defineProperty(tree, 'batchUpdate', {
|
|
248
|
-
value: function (arg) {
|
|
249
|
-
if (arguments.length === 0) return;
|
|
250
|
-
if (typeof arg === 'function') {
|
|
251
|
-
const updater = arg;
|
|
252
|
-
const current = unwrap(signalState);
|
|
253
|
-
recursiveUpdate(signalState, updater(current));
|
|
254
|
-
} else {
|
|
255
|
-
recursiveUpdate(signalState, arg);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
enumerable: false,
|
|
259
|
-
writable: true,
|
|
260
|
-
configurable: true
|
|
261
|
-
});
|
|
262
|
-
for (const key of Object.keys(signalState)) {
|
|
263
|
-
if (!(key in tree)) {
|
|
264
|
-
Object.defineProperty(tree, key, {
|
|
265
|
-
value: signalState[key],
|
|
266
|
-
enumerable: true,
|
|
267
|
-
configurable: true
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return tree;
|
|
272
|
-
}
|
|
273
|
-
function signalTree(initialState, config = {}) {
|
|
274
|
-
return create(initialState, config);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export { isNodeAccessor, signalTree };
|
package/dist/lib/types.js
DELETED
package/dist/lib/utils.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { isSignal, signal, runInInjectionContext, effect } from '@angular/core';
|
|
2
|
-
import { isBuiltInObject } from '../is-built-in-object.js';
|
|
3
|
-
|
|
4
|
-
const CALLABLE_SIGNAL_SYMBOL = Symbol.for('SignalTree:NodeAccessor');
|
|
5
|
-
function isEntityMapMarker(value) {
|
|
6
|
-
return Boolean(value && typeof value === 'object' && value.__isEntityMap === true);
|
|
7
|
-
}
|
|
8
|
-
function isNodeAccessor(value) {
|
|
9
|
-
return typeof value === 'function' && value && CALLABLE_SIGNAL_SYMBOL in value;
|
|
10
|
-
}
|
|
11
|
-
function isAnySignal(value) {
|
|
12
|
-
return isSignal(value) || isNodeAccessor(value);
|
|
13
|
-
}
|
|
14
|
-
function toWritableSignal(node, injector) {
|
|
15
|
-
const sig = signal(node());
|
|
16
|
-
const originalSet = sig.set.bind(sig);
|
|
17
|
-
const runner = () => {
|
|
18
|
-
originalSet(node());
|
|
19
|
-
};
|
|
20
|
-
if (injector) {
|
|
21
|
-
runInInjectionContext(injector, () => effect(runner));
|
|
22
|
-
} else {
|
|
23
|
-
try {
|
|
24
|
-
effect(runner);
|
|
25
|
-
} catch {
|
|
26
|
-
console.warn('[SignalTree] toWritableSignal called without injection context; pass Injector for reactivity.');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
sig.set = value => {
|
|
30
|
-
node(value);
|
|
31
|
-
originalSet(value);
|
|
32
|
-
};
|
|
33
|
-
sig.update = updater => {
|
|
34
|
-
sig.set(updater(sig()));
|
|
35
|
-
};
|
|
36
|
-
return sig;
|
|
37
|
-
}
|
|
38
|
-
function composeEnhancers(...enhancers) {
|
|
39
|
-
return tree => enhancers.reduce((t, e) => e(t), tree);
|
|
40
|
-
}
|
|
41
|
-
function createLazySignalTree(obj, equalityFn, basePath = '', memoryManager) {
|
|
42
|
-
const signalCache = new Map();
|
|
43
|
-
const nestedProxies = new Map();
|
|
44
|
-
const nestedCleanups = new Map();
|
|
45
|
-
const cleanup = () => {
|
|
46
|
-
nestedCleanups.forEach(fn => {
|
|
47
|
-
try {
|
|
48
|
-
fn();
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.warn('Error during nested cleanup:', error);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
nestedCleanups.clear();
|
|
54
|
-
signalCache.clear();
|
|
55
|
-
nestedProxies.clear();
|
|
56
|
-
if (memoryManager) {
|
|
57
|
-
memoryManager.dispose();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const proxy = new Proxy(obj, {
|
|
61
|
-
get(target, prop) {
|
|
62
|
-
if (prop === '__cleanup__') return cleanup;
|
|
63
|
-
if (typeof prop === 'symbol') {
|
|
64
|
-
return target[prop];
|
|
65
|
-
}
|
|
66
|
-
if (prop === 'valueOf' || prop === 'toString') {
|
|
67
|
-
return target[prop];
|
|
68
|
-
}
|
|
69
|
-
const key = prop;
|
|
70
|
-
const path = basePath ? `${basePath}.${key}` : key;
|
|
71
|
-
if (!(key in target)) return undefined;
|
|
72
|
-
const value = target[key];
|
|
73
|
-
if (isSignal(value)) return value;
|
|
74
|
-
if (value && typeof value === 'object' && typeof value.addOne === 'function' && typeof value.all === 'function') {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
if (isEntityMapMarker(value)) return value;
|
|
78
|
-
if (memoryManager) {
|
|
79
|
-
const cached = memoryManager.getSignal(path);
|
|
80
|
-
if (cached) return cached;
|
|
81
|
-
}
|
|
82
|
-
if (signalCache.has(path)) return signalCache.get(path);
|
|
83
|
-
if (nestedProxies.has(path)) return nestedProxies.get(path);
|
|
84
|
-
if (value && typeof value === 'object' && !Array.isArray(value) && !isSignal(value) && !isBuiltInObject(value)) {
|
|
85
|
-
try {
|
|
86
|
-
const nestedProxy = createLazySignalTree(value, equalityFn, path, memoryManager);
|
|
87
|
-
nestedProxies.set(path, nestedProxy);
|
|
88
|
-
const proxyWithCleanup = nestedProxy;
|
|
89
|
-
if (typeof proxyWithCleanup.__cleanup__ === 'function') {
|
|
90
|
-
nestedCleanups.set(path, proxyWithCleanup.__cleanup__);
|
|
91
|
-
}
|
|
92
|
-
return nestedProxy;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.warn(`Failed to create lazy proxy for path "${path}":`, error);
|
|
95
|
-
const fallbackSignal = signal(value, {
|
|
96
|
-
equal: equalityFn
|
|
97
|
-
});
|
|
98
|
-
signalCache.set(path, fallbackSignal);
|
|
99
|
-
if (memoryManager) {
|
|
100
|
-
memoryManager.cacheSignal(path, fallbackSignal);
|
|
101
|
-
}
|
|
102
|
-
return fallbackSignal;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const newSignal = signal(value, {
|
|
107
|
-
equal: equalityFn
|
|
108
|
-
});
|
|
109
|
-
signalCache.set(path, newSignal);
|
|
110
|
-
if (memoryManager) {
|
|
111
|
-
memoryManager.cacheSignal(path, newSignal);
|
|
112
|
-
}
|
|
113
|
-
return newSignal;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.warn(`Failed to create signal for path "${path}":`, error);
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
set(target, prop, value) {
|
|
120
|
-
if (typeof prop === 'symbol') {
|
|
121
|
-
target[prop] = value;
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
const key = prop;
|
|
125
|
-
const path = basePath ? `${basePath}.${key}` : key;
|
|
126
|
-
try {
|
|
127
|
-
target[key] = value;
|
|
128
|
-
const cachedSignal = signalCache.get(path);
|
|
129
|
-
if (cachedSignal && 'set' in cachedSignal) {
|
|
130
|
-
cachedSignal.set(value);
|
|
131
|
-
}
|
|
132
|
-
if (nestedProxies.has(path)) {
|
|
133
|
-
const nestedCleanup = nestedCleanups.get(path);
|
|
134
|
-
if (nestedCleanup) {
|
|
135
|
-
nestedCleanup();
|
|
136
|
-
nestedCleanups.delete(path);
|
|
137
|
-
}
|
|
138
|
-
nestedProxies.delete(path);
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.warn(`Failed to set value for path "${path}":`, error);
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
has(target, prop) {
|
|
147
|
-
return prop in target;
|
|
148
|
-
},
|
|
149
|
-
ownKeys(target) {
|
|
150
|
-
return Reflect.ownKeys(target);
|
|
151
|
-
},
|
|
152
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
153
|
-
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return proxy;
|
|
157
|
-
}
|
|
158
|
-
function unwrap(node) {
|
|
159
|
-
if (node === null || node === undefined) {
|
|
160
|
-
return node;
|
|
161
|
-
}
|
|
162
|
-
if (isNodeAccessor(node)) {
|
|
163
|
-
const result = {};
|
|
164
|
-
for (const key in node) {
|
|
165
|
-
if (!Object.prototype.hasOwnProperty.call(node, key)) continue;
|
|
166
|
-
if (key === 'length' || key === 'prototype') continue;
|
|
167
|
-
if (key === 'name') {
|
|
168
|
-
const value = node[key];
|
|
169
|
-
if (!isSignal(value) && !isNodeAccessor(value)) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const value = node[key];
|
|
174
|
-
if (isNodeAccessor(value)) {
|
|
175
|
-
result[key] = unwrap(value);
|
|
176
|
-
} else if (isSignal(value)) {
|
|
177
|
-
const unwrappedValue = value();
|
|
178
|
-
if (typeof unwrappedValue === 'object' && unwrappedValue !== null && !Array.isArray(unwrappedValue) && !isBuiltInObject(unwrappedValue)) {
|
|
179
|
-
result[key] = unwrap(unwrappedValue);
|
|
180
|
-
} else {
|
|
181
|
-
result[key] = unwrappedValue;
|
|
182
|
-
}
|
|
183
|
-
} else if (typeof value === 'object' && value !== null && !Array.isArray(value) && !isBuiltInObject(value)) {
|
|
184
|
-
result[key] = unwrap(value);
|
|
185
|
-
} else {
|
|
186
|
-
result[key] = value;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
190
|
-
}
|
|
191
|
-
if (isSignal(node)) {
|
|
192
|
-
const value = node();
|
|
193
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value) && !isBuiltInObject(value)) {
|
|
194
|
-
return unwrap(value);
|
|
195
|
-
}
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
if (typeof node !== 'object') {
|
|
199
|
-
return node;
|
|
200
|
-
}
|
|
201
|
-
if (Array.isArray(node)) {
|
|
202
|
-
return node;
|
|
203
|
-
}
|
|
204
|
-
if (isBuiltInObject(node)) {
|
|
205
|
-
return node;
|
|
206
|
-
}
|
|
207
|
-
const result = {};
|
|
208
|
-
for (const key in node) {
|
|
209
|
-
if (!Object.prototype.hasOwnProperty.call(node, key)) continue;
|
|
210
|
-
if (key === 'set' || key === 'update') {
|
|
211
|
-
const v = node[key];
|
|
212
|
-
if (typeof v === 'function') continue;
|
|
213
|
-
}
|
|
214
|
-
const value = node[key];
|
|
215
|
-
if (isNodeAccessor(value)) {
|
|
216
|
-
const unwrappedValue = value();
|
|
217
|
-
if (typeof unwrappedValue === 'object' && unwrappedValue !== null && !Array.isArray(unwrappedValue) && !isBuiltInObject(unwrappedValue)) {
|
|
218
|
-
result[key] = unwrap(unwrappedValue);
|
|
219
|
-
} else {
|
|
220
|
-
result[key] = unwrappedValue;
|
|
221
|
-
}
|
|
222
|
-
} else if (isSignal(value)) {
|
|
223
|
-
const unwrappedValue = value();
|
|
224
|
-
if (typeof unwrappedValue === 'object' && unwrappedValue !== null && !Array.isArray(unwrappedValue) && !isBuiltInObject(unwrappedValue)) {
|
|
225
|
-
result[key] = unwrap(unwrappedValue);
|
|
226
|
-
} else {
|
|
227
|
-
result[key] = unwrappedValue;
|
|
228
|
-
}
|
|
229
|
-
} else if (typeof value === 'object' && value !== null && !Array.isArray(value) && !isBuiltInObject(value)) {
|
|
230
|
-
result[key] = unwrap(value);
|
|
231
|
-
} else {
|
|
232
|
-
result[key] = value;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const symbols = Object.getOwnPropertySymbols(node);
|
|
236
|
-
for (const sym of symbols) {
|
|
237
|
-
const value = node[sym];
|
|
238
|
-
if (isNodeAccessor(value)) {
|
|
239
|
-
const unwrappedValue = value();
|
|
240
|
-
if (typeof unwrappedValue === 'object' && unwrappedValue !== null && !Array.isArray(unwrappedValue) && !isBuiltInObject(unwrappedValue)) {
|
|
241
|
-
result[sym] = unwrap(unwrappedValue);
|
|
242
|
-
} else {
|
|
243
|
-
result[sym] = unwrappedValue;
|
|
244
|
-
}
|
|
245
|
-
} else if (isSignal(value)) {
|
|
246
|
-
const unwrappedValue = value();
|
|
247
|
-
if (typeof unwrappedValue === 'object' && unwrappedValue !== null && !Array.isArray(unwrappedValue) && !isBuiltInObject(unwrappedValue)) {
|
|
248
|
-
result[sym] = unwrap(unwrappedValue);
|
|
249
|
-
} else {
|
|
250
|
-
result[sym] = unwrappedValue;
|
|
251
|
-
}
|
|
252
|
-
} else if (typeof value === 'object' && value !== null && !Array.isArray(value) && !isBuiltInObject(value)) {
|
|
253
|
-
result[sym] = unwrap(value);
|
|
254
|
-
} else {
|
|
255
|
-
result[sym] = value;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return result;
|
|
259
|
-
}
|
|
260
|
-
function snapshotState(state) {
|
|
261
|
-
return unwrap(state);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export { composeEnhancers, createLazySignalTree, isAnySignal, isBuiltInObject, isEntityMapMarker, isNodeAccessor, snapshotState, toWritableSignal, unwrap };
|
package/dist/lru-cache.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
class LRUCache {
|
|
2
|
-
constructor(maxSize) {
|
|
3
|
-
this.maxSize = maxSize;
|
|
4
|
-
this.cache = new Map();
|
|
5
|
-
if (!Number.isFinite(maxSize) || maxSize <= 0) {
|
|
6
|
-
throw new Error('LRUCache maxSize must be a positive, finite number');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
set(key, value) {
|
|
10
|
-
if (this.cache.has(key)) {
|
|
11
|
-
this.cache.delete(key);
|
|
12
|
-
}
|
|
13
|
-
this.cache.set(key, value);
|
|
14
|
-
if (this.cache.size > this.maxSize) {
|
|
15
|
-
const oldestKey = this.cache.keys().next().value;
|
|
16
|
-
if (oldestKey !== undefined) {
|
|
17
|
-
this.cache.delete(oldestKey);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
get(key) {
|
|
22
|
-
if (!this.cache.has(key)) return undefined;
|
|
23
|
-
const value = this.cache.get(key);
|
|
24
|
-
if (value !== undefined) {
|
|
25
|
-
this.cache.delete(key);
|
|
26
|
-
this.cache.set(key, value);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
delete(key) {
|
|
31
|
-
this.cache.delete(key);
|
|
32
|
-
}
|
|
33
|
-
has(key) {
|
|
34
|
-
return this.cache.has(key);
|
|
35
|
-
}
|
|
36
|
-
clear() {
|
|
37
|
-
this.cache.clear();
|
|
38
|
-
}
|
|
39
|
-
size() {
|
|
40
|
-
return this.cache.size;
|
|
41
|
-
}
|
|
42
|
-
forEach(callback) {
|
|
43
|
-
this.cache.forEach((value, key) => callback(value, key));
|
|
44
|
-
}
|
|
45
|
-
entries() {
|
|
46
|
-
return this.cache.entries();
|
|
47
|
-
}
|
|
48
|
-
keys() {
|
|
49
|
-
return this.cache.keys();
|
|
50
|
-
}
|
|
51
|
-
resize(newSize) {
|
|
52
|
-
if (!Number.isFinite(newSize) || newSize <= 0) {
|
|
53
|
-
throw new Error('LRUCache newSize must be a positive, finite number');
|
|
54
|
-
}
|
|
55
|
-
this.maxSize = newSize;
|
|
56
|
-
while (this.cache.size > this.maxSize) {
|
|
57
|
-
const oldestKey = this.cache.keys().next().value;
|
|
58
|
-
if (oldestKey === undefined) break;
|
|
59
|
-
this.cache.delete(oldestKey);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { LRUCache };
|
package/dist/parse-path.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_PATH_CACHE_SIZE } from './constants.js';
|
|
2
|
-
import { LRUCache } from './lru-cache.js';
|
|
3
|
-
|
|
4
|
-
const pathCache = new LRUCache(DEFAULT_PATH_CACHE_SIZE);
|
|
5
|
-
function parsePath(path) {
|
|
6
|
-
const cached = pathCache.get(path);
|
|
7
|
-
if (cached) return cached;
|
|
8
|
-
const segments = path.split('.');
|
|
9
|
-
pathCache.set(path, segments);
|
|
10
|
-
return segments;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { parsePath };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ISignalTree, BatchingConfig, BatchingMethods } from '../../lib/types';
|
|
2
|
-
export declare function batching(config?: BatchingConfig): <T>(tree: ISignalTree<T>) => ISignalTree<T> & BatchingMethods<T>;
|
|
3
|
-
export declare function highPerformanceBatching(): <T>(tree: ISignalTree<T>) => ISignalTree<T> & BatchingMethods<T>;
|
|
4
|
-
export declare function batchingWithConfig(config?: BatchingConfig): <T>(tree: ISignalTree<T>) => ISignalTree<T> & BatchingMethods<T>;
|
|
5
|
-
export declare function flushBatchedUpdates(): void;
|
|
6
|
-
export declare function hasPendingUpdates(): boolean;
|
|
7
|
-
export declare function getBatchQueueSize(): number;
|
|
8
|
-
export declare const withBatching: ((config?: BatchingConfig) => <T>(tree: ISignalTree<T>) => ISignalTree<T> & BatchingMethods<T>) & {
|
|
9
|
-
highPerformance: typeof highPerformanceBatching;
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './batching';
|