@signaltree/core 5.1.6 → 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/enhancers/batching/{lib/batching.js → batching.js} +45 -17
- package/dist/enhancers/devtools/{lib/devtools.js → devtools.js} +83 -98
- package/dist/enhancers/effects/effects.js +66 -0
- package/dist/enhancers/entities/entities.js +51 -0
- package/dist/enhancers/memoization/{lib/memoization.js → memoization.js} +33 -23
- package/dist/enhancers/presets/lib/presets.js +5 -65
- package/dist/enhancers/serialization/{lib/serialization.js → serialization.js} +12 -18
- package/dist/enhancers/time-travel/{lib/time-travel.js → time-travel.js} +62 -24
- package/dist/enhancers/time-travel/utils.js +11 -0
- package/dist/index.js +8 -8
- package/dist/lib/async-helpers.js +6 -6
- package/dist/lib/presets.js +21 -0
- package/dist/lib/signal-tree.js +156 -496
- package/dist/lib/types.js +1 -1
- package/dist/lib/utils.js +40 -2
- package/package.json +1 -6
- package/src/enhancers/batching/batching.d.ts +11 -0
- package/src/enhancers/batching/index.d.ts +1 -1
- package/src/enhancers/devtools/{lib/devtools.d.ts → devtools.d.ts} +10 -19
- package/src/enhancers/devtools/devtools.types.d.ts +1 -0
- package/src/enhancers/devtools/index.d.ts +1 -1
- 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 -1
- package/src/enhancers/index.d.ts +3 -3
- package/src/enhancers/memoization/index.d.ts +1 -1
- package/src/enhancers/memoization/memoization.d.ts +54 -0
- package/src/enhancers/memoization/memoization.types.d.ts +1 -0
- package/src/enhancers/presets/lib/presets.d.ts +3 -6
- package/src/enhancers/serialization/index.d.ts +1 -1
- package/src/{serialization.d.ts → enhancers/serialization/serialization.d.ts} +17 -8
- package/src/enhancers/test-helpers/types-equals.d.ts +2 -0
- package/src/enhancers/time-travel/index.d.ts +1 -1
- 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 -74
- package/src/enhancers/typing/helpers-types.d.ts +2 -0
- package/src/index.d.ts +7 -8
- package/src/lib/async-helpers.d.ts +2 -2
- package/src/lib/dev-proxy.d.ts +3 -0
- package/src/lib/presets.d.ts +34 -0
- package/src/lib/signal-tree.d.ts +2 -7
- package/src/lib/types.d.ts +121 -90
- package/src/lib/utils.d.ts +4 -0
- package/dist/deep-clone.js +0 -80
- package/dist/enhancers/computed/lib/computed.js +0 -21
- package/dist/enhancers/entities/lib/entities.js +0 -66
- package/dist/lib/performance/diff-engine.js +0 -156
- package/dist/lib/performance/path-index.js +0 -156
- package/dist/lib/performance/update-engine.js +0 -188
- package/src/async-helpers.d.ts +0 -8
- package/src/batching.d.ts +0 -16
- package/src/computed.d.ts +0 -12
- package/src/constants.d.ts +0 -14
- package/src/devtools.d.ts +0 -77
- package/src/diff-engine.d.ts +0 -33
- package/src/enhancers/batching/lib/batching.d.ts +0 -16
- package/src/enhancers/computed/index.d.ts +0 -1
- package/src/enhancers/computed/lib/computed.d.ts +0 -12
- package/src/enhancers/entities/lib/entities.d.ts +0 -17
- package/src/enhancers/memoization/lib/memoization.d.ts +0 -65
- package/src/enhancers/presets/test-setup.d.ts +0 -3
- package/src/enhancers/serialization/lib/serialization.d.ts +0 -59
- package/src/enhancers/time-travel/lib/time-travel.d.ts +0 -36
- package/src/enhancers/time-travel/lib/utils.d.ts +0 -1
- package/src/entities.d.ts +0 -28
- package/src/memoization.d.ts +0 -65
- package/src/memory-manager.d.ts +0 -30
- package/src/path-index.d.ts +0 -25
- package/src/path-notifier.d.ts +0 -12
- package/src/presets.d.ts +0 -11
- package/src/security-validator.d.ts +0 -33
- package/src/signal-tree.d.ts +0 -8
- package/src/test-setup.d.ts +0 -3
- package/src/time-travel.d.ts +0 -36
- package/src/types.d.ts +0 -436
- package/src/update-engine.d.ts +0 -32
- package/src/utils.d.ts +0 -1
- /package/src/{entity-signal.d.ts → enhancers/batching/batching.types.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepEqual } from '
|
|
1
|
+
import { snapshotState } from '../../lib/utils.js';
|
|
2
|
+
import { deepClone, deepEqual } from './utils.js';
|
|
3
3
|
|
|
4
4
|
class TimeTravelManager {
|
|
5
5
|
tree;
|
|
@@ -28,8 +28,10 @@ class TimeTravelManager {
|
|
|
28
28
|
if (this.currentIndex < this.history.length - 1) {
|
|
29
29
|
this.history = this.history.slice(0, this.currentIndex + 1);
|
|
30
30
|
}
|
|
31
|
+
const plain = snapshotState(this.tree.state);
|
|
32
|
+
const cloned = typeof structuredClone !== 'undefined' ? structuredClone(plain) : JSON.parse(JSON.stringify(plain));
|
|
31
33
|
const entry = {
|
|
32
|
-
state:
|
|
34
|
+
state: cloned,
|
|
33
35
|
timestamp: Date.now(),
|
|
34
36
|
action: this.actionNames[action] || action,
|
|
35
37
|
...(this.includePayload && payload !== undefined && {
|
|
@@ -99,8 +101,33 @@ class TimeTravelManager {
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
function
|
|
104
|
+
function timeTravel(config = {}) {
|
|
105
|
+
const {
|
|
106
|
+
enabled = true
|
|
107
|
+
} = config;
|
|
103
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
|
+
}
|
|
104
131
|
const originalTreeCall = tree.bind(tree);
|
|
105
132
|
let isRestoring = false;
|
|
106
133
|
const timeTravelManager = new TimeTravelManager(tree, config, state => {
|
|
@@ -137,8 +164,7 @@ function withTimeTravel(config = {}) {
|
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
166
|
const afterState = originalTreeCall();
|
|
140
|
-
|
|
141
|
-
if (!statesEqual) {
|
|
167
|
+
if (!deepEqual(beforeState, afterState)) {
|
|
142
168
|
timeTravelManager.addEntry('update', afterState);
|
|
143
169
|
}
|
|
144
170
|
return result;
|
|
@@ -155,39 +181,51 @@ function withTimeTravel(config = {}) {
|
|
|
155
181
|
}
|
|
156
182
|
if ('$' in tree) {
|
|
157
183
|
Object.defineProperty(enhancedTree, '$', {
|
|
158
|
-
value: tree
|
|
184
|
+
value: tree.$,
|
|
159
185
|
enumerable: false,
|
|
160
186
|
configurable: true
|
|
161
187
|
});
|
|
162
188
|
}
|
|
163
|
-
enhancedTree
|
|
189
|
+
enhancedTree['undo'] = () => {
|
|
164
190
|
timeTravelManager.undo();
|
|
165
191
|
};
|
|
166
|
-
enhancedTree
|
|
192
|
+
enhancedTree['redo'] = () => {
|
|
167
193
|
timeTravelManager.redo();
|
|
168
194
|
};
|
|
169
|
-
enhancedTree
|
|
170
|
-
enhancedTree
|
|
195
|
+
enhancedTree['getHistory'] = () => timeTravelManager.getHistory();
|
|
196
|
+
enhancedTree['resetHistory'] = () => {
|
|
171
197
|
timeTravelManager.resetHistory();
|
|
172
198
|
};
|
|
173
|
-
enhancedTree
|
|
199
|
+
enhancedTree['jumpTo'] = index => {
|
|
174
200
|
timeTravelManager.jumpTo(index);
|
|
175
201
|
};
|
|
176
|
-
enhancedTree
|
|
177
|
-
enhancedTree
|
|
178
|
-
enhancedTree
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
202
|
+
enhancedTree['canUndo'] = () => timeTravelManager.canUndo();
|
|
203
|
+
enhancedTree['canRedo'] = () => timeTravelManager.canRedo();
|
|
204
|
+
enhancedTree['getCurrentIndex'] = () => timeTravelManager.getCurrentIndex();
|
|
205
|
+
enhancedTree['__timeTravel'] = timeTravelManager;
|
|
206
|
+
return enhancedTree;
|
|
182
207
|
};
|
|
183
208
|
}
|
|
184
|
-
function enableTimeTravel(
|
|
185
|
-
return
|
|
186
|
-
|
|
209
|
+
function enableTimeTravel() {
|
|
210
|
+
return timeTravel({
|
|
211
|
+
enabled: true
|
|
187
212
|
});
|
|
188
213
|
}
|
|
189
|
-
function
|
|
190
|
-
return
|
|
214
|
+
function timeTravelHistory(maxHistorySize) {
|
|
215
|
+
return timeTravel({
|
|
216
|
+
maxHistorySize
|
|
217
|
+
});
|
|
191
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
|
+
});
|
|
192
230
|
|
|
193
|
-
export { enableTimeTravel,
|
|
231
|
+
export { enableTimeTravel, timeTravel, timeTravelHistory };
|
|
@@ -0,0 +1,11 @@
|
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -4,16 +4,16 @@ export { composeEnhancers, createLazySignalTree, isAnySignal, isNodeAccessor, to
|
|
|
4
4
|
export { getPathNotifier } from './lib/path-notifier.js';
|
|
5
5
|
export { SecurityPresets, SecurityValidator } from './lib/security/security-validator.js';
|
|
6
6
|
export { createEnhancer, resolveEnhancerOrder } from './enhancers/index.js';
|
|
7
|
-
export { flushBatchedUpdates, getBatchQueueSize, hasPendingUpdates,
|
|
8
|
-
export {
|
|
9
|
-
export { enableTimeTravel,
|
|
10
|
-
export { enableEntities,
|
|
11
|
-
export { applyPersistence, applySerialization, createIndexedDBAdapter, createStorageAdapter, enableSerialization,
|
|
12
|
-
export {
|
|
7
|
+
export { batching, flushBatchedUpdates, getBatchQueueSize, hasPendingUpdates, highPerformanceBatching } from './enhancers/batching/batching.js';
|
|
8
|
+
export { clearAllCaches, computedMemoization, deepStateMemoization, getGlobalCacheStats, highFrequencyMemoization, highPerformanceMemoization, lightweightMemoization, memoization, memoize, memoizeReference, memoizeShallow, selectorMemoization, shallowMemoization } from './enhancers/memoization/memoization.js';
|
|
9
|
+
export { enableTimeTravel, timeTravel } from './enhancers/time-travel/time-travel.js';
|
|
10
|
+
export { enableEntities, entities, highPerformanceEntities } from './enhancers/entities/entities.js';
|
|
11
|
+
export { applyPersistence, applySerialization, createIndexedDBAdapter, createStorageAdapter, enableSerialization, persistence, serialization } from './enhancers/serialization/serialization.js';
|
|
12
|
+
export { devTools, enableDevTools, fullDevTools, productionDevTools } from './enhancers/devtools/devtools.js';
|
|
13
13
|
export { createAsyncOperation, trackAsync } from './lib/async-helpers.js';
|
|
14
|
-
export { TREE_PRESETS, combinePresets,
|
|
15
|
-
export { computedEnhancer, createComputed } from './enhancers/computed/lib/computed.js';
|
|
14
|
+
export { TREE_PRESETS, combinePresets, createPresetConfig, getAvailablePresets, validatePreset } from './enhancers/presets/lib/presets.js';
|
|
16
15
|
export { SIGNAL_TREE_CONSTANTS, SIGNAL_TREE_MESSAGES } from './lib/constants.js';
|
|
17
16
|
export { deepEqual, deepEqual as equal } from './deep-equal.js';
|
|
18
17
|
export { parsePath } from './parse-path.js';
|
|
19
18
|
export { isBuiltInObject } from './is-built-in-object.js';
|
|
19
|
+
export { createDevTree } from './lib/presets.js';
|
|
@@ -2,11 +2,11 @@ import { signal } from '@angular/core';
|
|
|
2
2
|
|
|
3
3
|
function createAsyncOperation(name, operation) {
|
|
4
4
|
return async tree => {
|
|
5
|
-
if (typeof tree
|
|
5
|
+
if (typeof tree['batchUpdate'] === 'function') {
|
|
6
6
|
const pendingPatch = {
|
|
7
7
|
[`${name}_PENDING`]: true
|
|
8
8
|
};
|
|
9
|
-
tree
|
|
9
|
+
tree['batchUpdate'](() => pendingPatch);
|
|
10
10
|
} else if ('$' in tree) {
|
|
11
11
|
try {
|
|
12
12
|
tree['$'][`${name}_PENDING`]?.set?.(true);
|
|
@@ -15,12 +15,12 @@ function createAsyncOperation(name, operation) {
|
|
|
15
15
|
}
|
|
16
16
|
try {
|
|
17
17
|
const result = await operation();
|
|
18
|
-
if (typeof tree
|
|
18
|
+
if (typeof tree['batchUpdate'] === 'function') {
|
|
19
19
|
const resultPatch = {
|
|
20
20
|
[`${name}_RESULT`]: result,
|
|
21
21
|
[`${name}_PENDING`]: false
|
|
22
22
|
};
|
|
23
|
-
tree
|
|
23
|
+
tree['batchUpdate'](() => resultPatch);
|
|
24
24
|
} else if ('$' in tree) {
|
|
25
25
|
try {
|
|
26
26
|
tree['$'][`${name}_RESULT`]?.set?.(result);
|
|
@@ -31,12 +31,12 @@ function createAsyncOperation(name, operation) {
|
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
33
|
} catch (error) {
|
|
34
|
-
if (typeof tree
|
|
34
|
+
if (typeof tree['batchUpdate'] === 'function') {
|
|
35
35
|
const errorPatch = {
|
|
36
36
|
[`${name}_ERROR`]: error,
|
|
37
37
|
[`${name}_PENDING`]: false
|
|
38
38
|
};
|
|
39
|
-
tree
|
|
39
|
+
tree['batchUpdate'](() => errorPatch);
|
|
40
40
|
} else if ('$' in tree) {
|
|
41
41
|
try {
|
|
42
42
|
tree['$'][`${name}_ERROR`]?.set?.(error);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { signalTree } from './signal-tree.js';
|
|
2
|
+
import { effects } from '../enhancers/effects/effects.js';
|
|
3
|
+
import { batching } from '../enhancers/batching/batching.js';
|
|
4
|
+
import { memoization } from '../enhancers/memoization/memoization.js';
|
|
5
|
+
import { entities } from '../enhancers/entities/entities.js';
|
|
6
|
+
import { timeTravel } from '../enhancers/time-travel/time-travel.js';
|
|
7
|
+
import { devTools } from '../enhancers/devtools/devtools.js';
|
|
8
|
+
|
|
9
|
+
function createDevTree(initialState, config = {}) {
|
|
10
|
+
if (arguments.length === 0) {
|
|
11
|
+
const enhancer = tree => tree.with(effects()).with(batching()).with(memoization()).with(entities()).with(timeTravel()).with(devTools());
|
|
12
|
+
return {
|
|
13
|
+
enhancer
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const base = signalTree(initialState, config);
|
|
17
|
+
const enhanced = base.with(effects()).with(batching(config.batching)).with(memoization(config.memoization)).with(entities()).with(timeTravel(config.timeTravel)).with(devTools(config.devTools));
|
|
18
|
+
return enhanced;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { createDevTree };
|