@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
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { snapshotState } from '../../lib/utils.js';
|
|
2
|
-
import { deepClone, deepEqual } from './utils.js';
|
|
3
|
-
|
|
4
|
-
class TimeTravelManager {
|
|
5
|
-
tree;
|
|
6
|
-
config;
|
|
7
|
-
restoreStateFn;
|
|
8
|
-
history = [];
|
|
9
|
-
currentIndex = -1;
|
|
10
|
-
maxHistorySize;
|
|
11
|
-
includePayload;
|
|
12
|
-
actionNames;
|
|
13
|
-
constructor(tree, config = {}, restoreStateFn) {
|
|
14
|
-
this.tree = tree;
|
|
15
|
-
this.config = config;
|
|
16
|
-
this.restoreStateFn = restoreStateFn;
|
|
17
|
-
this.maxHistorySize = config.maxHistorySize ?? 50;
|
|
18
|
-
this.includePayload = config.includePayload ?? true;
|
|
19
|
-
this.actionNames = {
|
|
20
|
-
update: 'UPDATE',
|
|
21
|
-
set: 'SET',
|
|
22
|
-
batch: 'BATCH',
|
|
23
|
-
...config.actionNames
|
|
24
|
-
};
|
|
25
|
-
this.addEntry('INIT', this.tree());
|
|
26
|
-
}
|
|
27
|
-
addEntry(action, state, payload) {
|
|
28
|
-
if (this.currentIndex < this.history.length - 1) {
|
|
29
|
-
this.history = this.history.slice(0, this.currentIndex + 1);
|
|
30
|
-
}
|
|
31
|
-
const plain = snapshotState(this.tree.state);
|
|
32
|
-
const cloned = typeof structuredClone !== 'undefined' ? structuredClone(plain) : JSON.parse(JSON.stringify(plain));
|
|
33
|
-
const entry = {
|
|
34
|
-
state: cloned,
|
|
35
|
-
timestamp: Date.now(),
|
|
36
|
-
action: this.actionNames[action] || action,
|
|
37
|
-
...(this.includePayload && payload !== undefined && {
|
|
38
|
-
payload
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
this.history.push(entry);
|
|
42
|
-
this.currentIndex = this.history.length - 1;
|
|
43
|
-
if (this.history.length > this.maxHistorySize) {
|
|
44
|
-
this.history.shift();
|
|
45
|
-
this.currentIndex--;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
undo() {
|
|
49
|
-
if (!this.canUndo()) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
this.currentIndex--;
|
|
53
|
-
const entry = this.history[this.currentIndex];
|
|
54
|
-
this.restoreState(entry.state);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
redo() {
|
|
58
|
-
if (!this.canRedo()) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
this.currentIndex++;
|
|
62
|
-
const entry = this.history[this.currentIndex];
|
|
63
|
-
this.restoreState(entry.state);
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
getHistory() {
|
|
67
|
-
return this.history.map(entry => ({
|
|
68
|
-
...entry,
|
|
69
|
-
state: deepClone(entry.state)
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
resetHistory() {
|
|
73
|
-
const currentState = this.tree();
|
|
74
|
-
this.history = [];
|
|
75
|
-
this.currentIndex = -1;
|
|
76
|
-
this.addEntry('RESET', currentState);
|
|
77
|
-
}
|
|
78
|
-
jumpTo(index) {
|
|
79
|
-
if (index < 0 || index >= this.history.length) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
this.currentIndex = index;
|
|
83
|
-
const entry = this.history[index];
|
|
84
|
-
this.restoreState(entry.state);
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
getCurrentIndex() {
|
|
88
|
-
return this.currentIndex;
|
|
89
|
-
}
|
|
90
|
-
canUndo() {
|
|
91
|
-
return this.currentIndex > 0;
|
|
92
|
-
}
|
|
93
|
-
canRedo() {
|
|
94
|
-
return this.currentIndex < this.history.length - 1;
|
|
95
|
-
}
|
|
96
|
-
restoreState(state) {
|
|
97
|
-
if (this.restoreStateFn) {
|
|
98
|
-
this.restoreStateFn(state);
|
|
99
|
-
} else {
|
|
100
|
-
this.tree(state);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function timeTravel(config = {}) {
|
|
105
|
-
const {
|
|
106
|
-
enabled = true
|
|
107
|
-
} = config;
|
|
108
|
-
return tree => {
|
|
109
|
-
if (!enabled) {
|
|
110
|
-
const noopMethods = {
|
|
111
|
-
undo() {},
|
|
112
|
-
redo() {},
|
|
113
|
-
canUndo() {
|
|
114
|
-
return false;
|
|
115
|
-
},
|
|
116
|
-
canRedo() {
|
|
117
|
-
return false;
|
|
118
|
-
},
|
|
119
|
-
getHistory() {
|
|
120
|
-
return [];
|
|
121
|
-
},
|
|
122
|
-
resetHistory() {},
|
|
123
|
-
jumpTo(_index) {
|
|
124
|
-
},
|
|
125
|
-
getCurrentIndex() {
|
|
126
|
-
return -1;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
return Object.assign(tree, noopMethods);
|
|
130
|
-
}
|
|
131
|
-
const originalTreeCall = tree.bind(tree);
|
|
132
|
-
let isRestoring = false;
|
|
133
|
-
const timeTravelManager = new TimeTravelManager(tree, config, state => {
|
|
134
|
-
isRestoring = true;
|
|
135
|
-
try {
|
|
136
|
-
originalTreeCall(state);
|
|
137
|
-
} finally {
|
|
138
|
-
isRestoring = false;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
const enhancedTree = function (...args) {
|
|
142
|
-
if (args.length === 0) {
|
|
143
|
-
return originalTreeCall();
|
|
144
|
-
} else {
|
|
145
|
-
if (isRestoring) {
|
|
146
|
-
if (args.length === 1) {
|
|
147
|
-
const arg = args[0];
|
|
148
|
-
if (typeof arg === 'function') {
|
|
149
|
-
return originalTreeCall(arg);
|
|
150
|
-
} else {
|
|
151
|
-
return originalTreeCall(arg);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const beforeState = originalTreeCall();
|
|
157
|
-
let result;
|
|
158
|
-
if (args.length === 1) {
|
|
159
|
-
const arg = args[0];
|
|
160
|
-
if (typeof arg === 'function') {
|
|
161
|
-
result = originalTreeCall(arg);
|
|
162
|
-
} else {
|
|
163
|
-
result = originalTreeCall(arg);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const afterState = originalTreeCall();
|
|
167
|
-
if (!deepEqual(beforeState, afterState)) {
|
|
168
|
-
timeTravelManager.addEntry('update', afterState);
|
|
169
|
-
}
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
Object.setPrototypeOf(enhancedTree, Object.getPrototypeOf(tree));
|
|
174
|
-
Object.assign(enhancedTree, tree);
|
|
175
|
-
if ('state' in tree) {
|
|
176
|
-
Object.defineProperty(enhancedTree, 'state', {
|
|
177
|
-
value: tree.state,
|
|
178
|
-
enumerable: false,
|
|
179
|
-
configurable: true
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if ('$' in tree) {
|
|
183
|
-
Object.defineProperty(enhancedTree, '$', {
|
|
184
|
-
value: tree.$,
|
|
185
|
-
enumerable: false,
|
|
186
|
-
configurable: true
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
enhancedTree['undo'] = () => {
|
|
190
|
-
timeTravelManager.undo();
|
|
191
|
-
};
|
|
192
|
-
enhancedTree['redo'] = () => {
|
|
193
|
-
timeTravelManager.redo();
|
|
194
|
-
};
|
|
195
|
-
enhancedTree['getHistory'] = () => timeTravelManager.getHistory();
|
|
196
|
-
enhancedTree['resetHistory'] = () => {
|
|
197
|
-
timeTravelManager.resetHistory();
|
|
198
|
-
};
|
|
199
|
-
enhancedTree['jumpTo'] = index => {
|
|
200
|
-
timeTravelManager.jumpTo(index);
|
|
201
|
-
};
|
|
202
|
-
enhancedTree['canUndo'] = () => timeTravelManager.canUndo();
|
|
203
|
-
enhancedTree['canRedo'] = () => timeTravelManager.canRedo();
|
|
204
|
-
enhancedTree['getCurrentIndex'] = () => timeTravelManager.getCurrentIndex();
|
|
205
|
-
enhancedTree['__timeTravel'] = timeTravelManager;
|
|
206
|
-
return enhancedTree;
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function enableTimeTravel() {
|
|
210
|
-
return timeTravel({
|
|
211
|
-
enabled: true
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function timeTravelHistory(maxHistorySize) {
|
|
215
|
-
return timeTravel({
|
|
216
|
-
maxHistorySize
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
Object.assign((config = {}) => timeTravel(config), {
|
|
220
|
-
minimal: () => timeTravel({
|
|
221
|
-
maxHistorySize: 20,
|
|
222
|
-
includePayload: false
|
|
223
|
-
}),
|
|
224
|
-
debug: () => timeTravel({
|
|
225
|
-
maxHistorySize: 200,
|
|
226
|
-
includePayload: true
|
|
227
|
-
}),
|
|
228
|
-
history: timeTravelHistory
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
export { enableTimeTravel, timeTravel, timeTravelHistory };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
function deepClone(obj) {
|
|
2
|
-
if (typeof structuredClone === 'function') {
|
|
3
|
-
return structuredClone(obj);
|
|
4
|
-
}
|
|
5
|
-
return JSON.parse(JSON.stringify(obj));
|
|
6
|
-
}
|
|
7
|
-
function deepEqual(a, b) {
|
|
8
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { deepClone, deepEqual };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function copyTreeProperties(source, target) {
|
|
2
|
-
const skipKeys = new Set(['state', '$']);
|
|
3
|
-
for (const key of Object.getOwnPropertyNames(source)) {
|
|
4
|
-
if (skipKeys.has(key)) continue;
|
|
5
|
-
if (Object.prototype.hasOwnProperty.call(target, key)) continue;
|
|
6
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
7
|
-
if (!descriptor) continue;
|
|
8
|
-
if (descriptor.configurable === false) continue;
|
|
9
|
-
Object.defineProperty(target, key, descriptor);
|
|
10
|
-
}
|
|
11
|
-
for (const sym of Object.getOwnPropertySymbols(source)) {
|
|
12
|
-
if (Object.prototype.hasOwnProperty.call(target, sym)) continue;
|
|
13
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, sym);
|
|
14
|
-
if (!descriptor) continue;
|
|
15
|
-
if (descriptor.configurable === false) continue;
|
|
16
|
-
Object.defineProperty(target, sym, descriptor);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { copyTreeProperties };
|
package/dist/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export { signalTree } from './lib/signal-tree.js';
|
|
2
|
-
export { ENHANCER_META, entityMap } from './lib/types.js';
|
|
3
|
-
export { composeEnhancers, createLazySignalTree, isAnySignal, isNodeAccessor, toWritableSignal } from './lib/utils.js';
|
|
4
|
-
export { createEditSession } from './lib/edit-session.js';
|
|
5
|
-
export { getPathNotifier } from './lib/path-notifier.js';
|
|
6
|
-
export { SecurityPresets, SecurityValidator } from './lib/security/security-validator.js';
|
|
7
|
-
export { createEnhancer, resolveEnhancerOrder } from './enhancers/index.js';
|
|
8
|
-
export { batching, batchingWithConfig, flushBatchedUpdates, getBatchQueueSize, hasPendingUpdates, highPerformanceBatching } from './enhancers/batching/batching.js';
|
|
9
|
-
export { clearAllCaches, computedMemoization, deepStateMemoization, getGlobalCacheStats, highFrequencyMemoization, highPerformanceMemoization, lightweightMemoization, memoization, memoize, memoizeReference, memoizeShallow, selectorMemoization, shallowMemoization } from './enhancers/memoization/memoization.js';
|
|
10
|
-
export { enableTimeTravel, timeTravel } from './enhancers/time-travel/time-travel.js';
|
|
11
|
-
export { enableEntities, entities, highPerformanceEntities } from './enhancers/entities/entities.js';
|
|
12
|
-
export { applyPersistence, applySerialization, createIndexedDBAdapter, createStorageAdapter, enableSerialization, persistence, serialization } from './enhancers/serialization/serialization.js';
|
|
13
|
-
export { devTools, enableDevTools, fullDevTools, productionDevTools } from './enhancers/devtools/devtools.js';
|
|
14
|
-
export { createAsyncOperation, trackAsync } from './lib/async-helpers.js';
|
|
15
|
-
export { TREE_PRESETS, combinePresets, createPresetConfig, getAvailablePresets, validatePreset } from './enhancers/presets/lib/presets.js';
|
|
16
|
-
export { SIGNAL_TREE_CONSTANTS, SIGNAL_TREE_MESSAGES } from './lib/constants.js';
|
|
17
|
-
export { deepEqual, deepEqual as equal } from './deep-equal.js';
|
|
18
|
-
export { parsePath } from './parse-path.js';
|
|
19
|
-
export { isBuiltInObject } from './is-built-in-object.js';
|
|
20
|
-
export { createDevTree } from './lib/presets.js';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function isBuiltInObject(value) {
|
|
2
|
-
if (value === null || value === undefined) return false;
|
|
3
|
-
if (value instanceof Date || value instanceof RegExp || typeof value === 'function' || value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet || value instanceof ArrayBuffer || value instanceof DataView || value instanceof Error || value instanceof Promise) {
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
if (value instanceof Int8Array || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int16Array || value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Float32Array || value instanceof Float64Array || value instanceof BigInt64Array || value instanceof BigUint64Array) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (typeof window !== 'undefined') {
|
|
10
|
-
if (value instanceof URL || value instanceof URLSearchParams || value instanceof FormData || value instanceof Blob || typeof File !== 'undefined' && value instanceof File || typeof FileList !== 'undefined' && value instanceof FileList || typeof Headers !== 'undefined' && value instanceof Headers || typeof Request !== 'undefined' && value instanceof Request || typeof Response !== 'undefined' && value instanceof Response || typeof AbortController !== 'undefined' && value instanceof AbortController || typeof AbortSignal !== 'undefined' && value instanceof AbortSignal) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
const NodeBuffer = globalThis === null || globalThis === void 0 ? void 0 : globalThis.Buffer;
|
|
16
|
-
if (NodeBuffer && value instanceof NodeBuffer) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
} catch (_a) {}
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { isBuiltInObject };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { signal } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
function createAsyncOperation(name, operation) {
|
|
4
|
-
return async tree => {
|
|
5
|
-
if (typeof tree['batchUpdate'] === 'function') {
|
|
6
|
-
const pendingPatch = {
|
|
7
|
-
[`${name}_PENDING`]: true
|
|
8
|
-
};
|
|
9
|
-
tree['batchUpdate'](() => pendingPatch);
|
|
10
|
-
} else if ('$' in tree) {
|
|
11
|
-
try {
|
|
12
|
-
tree['$'][`${name}_PENDING`]?.set?.(true);
|
|
13
|
-
} catch (e) {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const result = await operation();
|
|
18
|
-
if (typeof tree['batchUpdate'] === 'function') {
|
|
19
|
-
const resultPatch = {
|
|
20
|
-
[`${name}_RESULT`]: result,
|
|
21
|
-
[`${name}_PENDING`]: false
|
|
22
|
-
};
|
|
23
|
-
tree['batchUpdate'](() => resultPatch);
|
|
24
|
-
} else if ('$' in tree) {
|
|
25
|
-
try {
|
|
26
|
-
tree['$'][`${name}_RESULT`]?.set?.(result);
|
|
27
|
-
tree['$'][`${name}_PENDING`]?.set?.(false);
|
|
28
|
-
} catch (e) {
|
|
29
|
-
void e;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (typeof tree['batchUpdate'] === 'function') {
|
|
35
|
-
const errorPatch = {
|
|
36
|
-
[`${name}_ERROR`]: error,
|
|
37
|
-
[`${name}_PENDING`]: false
|
|
38
|
-
};
|
|
39
|
-
tree['batchUpdate'](() => errorPatch);
|
|
40
|
-
} else if ('$' in tree) {
|
|
41
|
-
try {
|
|
42
|
-
tree['$'][`${name}_ERROR`]?.set?.(error);
|
|
43
|
-
tree['$'][`${name}_PENDING`]?.set?.(false);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function trackAsync(operation) {
|
|
52
|
-
const pending = signal(false);
|
|
53
|
-
const error = signal(null);
|
|
54
|
-
const result = signal(null);
|
|
55
|
-
return {
|
|
56
|
-
pending: pending.asReadonly(),
|
|
57
|
-
error: error.asReadonly(),
|
|
58
|
-
result: result.asReadonly(),
|
|
59
|
-
execute: async () => {
|
|
60
|
-
pending.set(true);
|
|
61
|
-
error.set(null);
|
|
62
|
-
try {
|
|
63
|
-
const res = await operation();
|
|
64
|
-
result.set(res);
|
|
65
|
-
return res;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
const err = e instanceof Error ? e : new Error(String(e));
|
|
68
|
-
error.set(err);
|
|
69
|
-
throw err;
|
|
70
|
-
} finally {
|
|
71
|
-
pending.set(false);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export { createAsyncOperation, trackAsync };
|
package/dist/lib/constants.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_PATH_CACHE_SIZE } from '../constants.js';
|
|
2
|
-
|
|
3
|
-
const SIGNAL_TREE_CONSTANTS = {
|
|
4
|
-
MAX_PATH_CACHE_SIZE: DEFAULT_PATH_CACHE_SIZE,
|
|
5
|
-
LAZY_THRESHOLD: 50,
|
|
6
|
-
ESTIMATE_MAX_DEPTH: 3,
|
|
7
|
-
ESTIMATE_SAMPLE_SIZE_ARRAY: 3,
|
|
8
|
-
ESTIMATE_SAMPLE_SIZE_OBJECT: 5,
|
|
9
|
-
DEFAULT_CACHE_SIZE: 100,
|
|
10
|
-
DEFAULT_BATCH_SIZE: 10
|
|
11
|
-
};
|
|
12
|
-
const DEV_MESSAGES = {
|
|
13
|
-
NULL_OR_UNDEFINED: 'null/undefined',
|
|
14
|
-
CIRCULAR_REF: 'circular ref',
|
|
15
|
-
UPDATER_INVALID: 'updater invalid',
|
|
16
|
-
LAZY_FALLBACK: 'lazy fallback',
|
|
17
|
-
SIGNAL_CREATION_FAILED: 'signal creation failed',
|
|
18
|
-
UPDATE_PATH_NOT_FOUND: 'update path not found',
|
|
19
|
-
UPDATE_FAILED: 'update failed',
|
|
20
|
-
ROLLBACK_FAILED: 'rollback failed',
|
|
21
|
-
CLEANUP_ERROR: 'cleanup error',
|
|
22
|
-
PRESET_UNKNOWN: 'unknown preset',
|
|
23
|
-
STRATEGY_SELECTION: 'strategy select',
|
|
24
|
-
TREE_DESTROYED: 'destroyed',
|
|
25
|
-
UPDATE_TRANSACTION: 'update tx',
|
|
26
|
-
BATCH_NOT_ENABLED: 'batching disabled',
|
|
27
|
-
MEMOIZE_NOT_ENABLED: 'memoize disabled',
|
|
28
|
-
MIDDLEWARE_NOT_AVAILABLE: 'middleware missing',
|
|
29
|
-
ENTITY_HELPERS_NOT_AVAILABLE: 'entity helpers missing',
|
|
30
|
-
TIME_TRAVEL_NOT_AVAILABLE: 'time travel missing',
|
|
31
|
-
OPTIMIZE_NOT_AVAILABLE: 'optimize missing',
|
|
32
|
-
UPDATE_OPTIMIZED_NOT_AVAILABLE: 'update optimized missing',
|
|
33
|
-
CACHE_NOT_AVAILABLE: 'cache missing',
|
|
34
|
-
PERFORMANCE_NOT_ENABLED: 'performance disabled',
|
|
35
|
-
ENHANCER_ORDER_FAILED: 'enhancer order failed',
|
|
36
|
-
ENHANCER_CYCLE_DETECTED: 'enhancer cycle',
|
|
37
|
-
ENHANCER_REQUIREMENT_MISSING: 'enhancer req missing',
|
|
38
|
-
ENHANCER_PROVIDES_MISSING: 'enhancer provides missing',
|
|
39
|
-
ENHANCER_FAILED: 'enhancer failed',
|
|
40
|
-
ENHANCER_NOT_FUNCTION: 'enhancer not function',
|
|
41
|
-
EFFECT_NO_CONTEXT: 'no angular context',
|
|
42
|
-
SUBSCRIBE_NO_CONTEXT: 'no angular context'
|
|
43
|
-
};
|
|
44
|
-
const PROD_MESSAGES = (() => {
|
|
45
|
-
const out = {};
|
|
46
|
-
let i = 0;
|
|
47
|
-
for (const k of Object.keys(DEV_MESSAGES)) {
|
|
48
|
-
out[k] = String(i++);
|
|
49
|
-
}
|
|
50
|
-
return out;
|
|
51
|
-
})();
|
|
52
|
-
const _isProdByEnv = Boolean(typeof globalThis === 'object' && globalThis !== null && 'process' in globalThis && typeof globalThis.process === 'object' && 'env' in globalThis.process && globalThis.process.env.NODE_ENV === 'production');
|
|
53
|
-
const _isDev = typeof ngDevMode !== 'undefined' ? Boolean(ngDevMode) : !_isProdByEnv;
|
|
54
|
-
const SIGNAL_TREE_MESSAGES = Object.freeze(_isDev ? DEV_MESSAGES : PROD_MESSAGES);
|
|
55
|
-
|
|
56
|
-
export { SIGNAL_TREE_CONSTANTS, SIGNAL_TREE_MESSAGES };
|
package/dist/lib/edit-session.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { signal } from '@angular/core';
|
|
2
|
-
import { deepEqual } from '../deep-equal.js';
|
|
3
|
-
|
|
4
|
-
function clone(value) {
|
|
5
|
-
try {
|
|
6
|
-
return globalThis.structuredClone ? globalThis.structuredClone(value) : JSON.parse(JSON.stringify(value));
|
|
7
|
-
} catch {
|
|
8
|
-
return JSON.parse(JSON.stringify(value));
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function createEditSession(initial) {
|
|
12
|
-
const original = signal(clone(initial));
|
|
13
|
-
const present = signal(clone(initial));
|
|
14
|
-
const pastCount = signal(0);
|
|
15
|
-
const futureCount = signal(0);
|
|
16
|
-
let past = [];
|
|
17
|
-
let future = [];
|
|
18
|
-
function updateCounts() {
|
|
19
|
-
pastCount.set(past.length);
|
|
20
|
-
futureCount.set(future.length);
|
|
21
|
-
}
|
|
22
|
-
const canUndo = () => pastCount() > 0;
|
|
23
|
-
const canRedo = () => futureCount() > 0;
|
|
24
|
-
const isDirty = () => !deepEqual(original(), present());
|
|
25
|
-
function setOriginal(value) {
|
|
26
|
-
const v = clone(value);
|
|
27
|
-
original.set(v);
|
|
28
|
-
present.set(clone(v));
|
|
29
|
-
past = [];
|
|
30
|
-
future = [];
|
|
31
|
-
updateCounts();
|
|
32
|
-
}
|
|
33
|
-
function applyChanges(valueOrUpdater) {
|
|
34
|
-
const current = present();
|
|
35
|
-
const next = typeof valueOrUpdater === 'function' ? valueOrUpdater(clone(current)) : valueOrUpdater;
|
|
36
|
-
if (deepEqual(current, next)) return;
|
|
37
|
-
past.push(clone(current));
|
|
38
|
-
present.set(clone(next));
|
|
39
|
-
future = [];
|
|
40
|
-
updateCounts();
|
|
41
|
-
}
|
|
42
|
-
function undo() {
|
|
43
|
-
if (past.length === 0) return;
|
|
44
|
-
const prev = past.pop();
|
|
45
|
-
future.push(clone(present()));
|
|
46
|
-
present.set(clone(prev));
|
|
47
|
-
updateCounts();
|
|
48
|
-
}
|
|
49
|
-
function redo() {
|
|
50
|
-
if (future.length === 0) return;
|
|
51
|
-
const next = future.pop();
|
|
52
|
-
past.push(clone(present()));
|
|
53
|
-
present.set(clone(next));
|
|
54
|
-
updateCounts();
|
|
55
|
-
}
|
|
56
|
-
function reset() {
|
|
57
|
-
present.set(clone(original()));
|
|
58
|
-
past = [];
|
|
59
|
-
future = [];
|
|
60
|
-
updateCounts();
|
|
61
|
-
}
|
|
62
|
-
function getHistory() {
|
|
63
|
-
return {
|
|
64
|
-
past: past.map(p => clone(p)),
|
|
65
|
-
present: clone(present()),
|
|
66
|
-
future: future.map(f => clone(f))
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
original,
|
|
71
|
-
modified: present,
|
|
72
|
-
canUndo,
|
|
73
|
-
canRedo,
|
|
74
|
-
isDirty,
|
|
75
|
-
setOriginal,
|
|
76
|
-
applyChanges,
|
|
77
|
-
undo,
|
|
78
|
-
redo,
|
|
79
|
-
reset,
|
|
80
|
-
getHistory
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { createEditSession, createEditSession as default };
|