@signaltree/core 5.1.4 → 6.0.0
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/package.json +1 -6
- package/dist/constants.js +0 -6
- package/dist/deep-clone.js +0 -80
- package/dist/deep-equal.js +0 -41
- package/dist/enhancers/batching/lib/batching.js +0 -161
- package/dist/enhancers/computed/lib/computed.js +0 -21
- package/dist/enhancers/devtools/lib/devtools.js +0 -321
- package/dist/enhancers/entities/lib/entities.js +0 -93
- package/dist/enhancers/index.js +0 -72
- package/dist/enhancers/memoization/lib/memoization.js +0 -410
- package/dist/enhancers/presets/lib/presets.js +0 -87
- package/dist/enhancers/serialization/constants.js +0 -15
- package/dist/enhancers/serialization/lib/serialization.js +0 -662
- package/dist/enhancers/time-travel/lib/time-travel.js +0 -193
- package/dist/index.js +0 -19
- 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/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/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/dist/lib/security/security-validator.js +0 -121
- package/dist/lib/signal-tree.js +0 -626
- package/dist/lib/types.js +0 -9
- package/dist/lib/utils.js +0 -261
- package/dist/lru-cache.js +0 -64
- package/dist/parse-path.js +0 -13
- 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/index.d.ts +0 -1
- package/src/enhancers/batching/lib/batching.d.ts +0 -16
- package/src/enhancers/batching/test-setup.d.ts +0 -3
- package/src/enhancers/computed/index.d.ts +0 -1
- package/src/enhancers/computed/lib/computed.d.ts +0 -12
- package/src/enhancers/devtools/index.d.ts +0 -1
- package/src/enhancers/devtools/lib/devtools.d.ts +0 -77
- package/src/enhancers/devtools/test-setup.d.ts +0 -3
- package/src/enhancers/entities/index.d.ts +0 -1
- package/src/enhancers/entities/lib/entities.d.ts +0 -20
- 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/lib/memoization.d.ts +0 -65
- 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 -11
- package/src/enhancers/presets/test-setup.d.ts +0 -3
- package/src/enhancers/serialization/constants.d.ts +0 -14
- package/src/enhancers/serialization/index.d.ts +0 -2
- package/src/enhancers/serialization/lib/serialization.d.ts +0 -59
- package/src/enhancers/serialization/test-setup.d.ts +0 -3
- package/src/enhancers/time-travel/index.d.ts +0 -1
- 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/enhancers/time-travel/test-setup.d.ts +0 -3
- package/src/enhancers/types.d.ts +0 -74
- package/src/entities.d.ts +0 -20
- package/src/entity-signal.d.ts +0 -1
- package/src/index.d.ts +0 -18
- package/src/lib/async-helpers.d.ts +0 -8
- package/src/lib/constants.d.ts +0 -41
- 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/security/security-validator.d.ts +0 -33
- package/src/lib/signal-tree.d.ts +0 -8
- package/src/lib/types.d.ts +0 -278
- package/src/lib/utils.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/serialization.d.ts +0 -59
- 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 -444
- package/src/update-engine.d.ts +0 -32
- package/src/utils.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signaltree/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
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,
|
|
@@ -23,11 +23,6 @@
|
|
|
23
23
|
"import": "./dist/enhancers/batching/index.js",
|
|
24
24
|
"default": "./dist/enhancers/batching/index.js"
|
|
25
25
|
},
|
|
26
|
-
"./enhancers/computed": {
|
|
27
|
-
"types": "./src/enhancers/computed/index.d.ts",
|
|
28
|
-
"import": "./dist/enhancers/computed/index.js",
|
|
29
|
-
"default": "./dist/enhancers/computed/index.js"
|
|
30
|
-
},
|
|
31
26
|
"./enhancers/middleware": {
|
|
32
27
|
"types": "./src/enhancers/middleware/index.d.ts",
|
|
33
28
|
"import": "./dist/enhancers/middleware/index.js",
|
package/dist/constants.js
DELETED
package/dist/deep-clone.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const globalStructuredClone = typeof globalThis === 'object' && globalThis !== null ? globalThis.structuredClone : undefined;
|
|
2
|
-
function deepClone(value) {
|
|
3
|
-
if (globalStructuredClone) {
|
|
4
|
-
try {
|
|
5
|
-
return globalStructuredClone(value);
|
|
6
|
-
} catch (_a) {}
|
|
7
|
-
}
|
|
8
|
-
return cloneValue(value, new WeakMap());
|
|
9
|
-
}
|
|
10
|
-
function cloneValue(value, seen) {
|
|
11
|
-
if (value === null || typeof value !== 'object') {
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === 'function') {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
const existing = seen.get(value);
|
|
18
|
-
if (existing) {
|
|
19
|
-
return existing;
|
|
20
|
-
}
|
|
21
|
-
if (value instanceof Date) {
|
|
22
|
-
return new Date(value.getTime());
|
|
23
|
-
}
|
|
24
|
-
if (value instanceof RegExp) {
|
|
25
|
-
return new RegExp(value.source, value.flags);
|
|
26
|
-
}
|
|
27
|
-
if (value instanceof Map) {
|
|
28
|
-
const result = new Map();
|
|
29
|
-
seen.set(value, result);
|
|
30
|
-
for (const [key, entryValue] of value) {
|
|
31
|
-
result.set(cloneValue(key, seen), cloneValue(entryValue, seen));
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
if (value instanceof Set) {
|
|
36
|
-
const result = new Set();
|
|
37
|
-
seen.set(value, result);
|
|
38
|
-
for (const entry of value) {
|
|
39
|
-
result.add(cloneValue(entry, seen));
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
if (Array.isArray(value)) {
|
|
44
|
-
const result = new Array(value.length);
|
|
45
|
-
seen.set(value, result);
|
|
46
|
-
for (let i = 0; i < value.length; i++) {
|
|
47
|
-
result[i] = cloneValue(value[i], seen);
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
if (ArrayBuffer.isView(value)) {
|
|
52
|
-
if (value instanceof DataView) {
|
|
53
|
-
const bufferClone = cloneValue(value.buffer, seen);
|
|
54
|
-
return new DataView(bufferClone, value.byteOffset, value.byteLength);
|
|
55
|
-
}
|
|
56
|
-
const viewWithSlice = value;
|
|
57
|
-
if (typeof viewWithSlice.slice === 'function') {
|
|
58
|
-
return viewWithSlice.slice();
|
|
59
|
-
}
|
|
60
|
-
const bufferClone = cloneValue(value.buffer, seen);
|
|
61
|
-
return new value.constructor(bufferClone, value.byteOffset, value.length);
|
|
62
|
-
}
|
|
63
|
-
if (value instanceof ArrayBuffer) {
|
|
64
|
-
return value.slice(0);
|
|
65
|
-
}
|
|
66
|
-
const proto = Object.getPrototypeOf(value);
|
|
67
|
-
const result = proto ? Object.create(proto) : {};
|
|
68
|
-
seen.set(value, result);
|
|
69
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
70
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
71
|
-
if (!descriptor) continue;
|
|
72
|
-
if ('value' in descriptor) {
|
|
73
|
-
descriptor.value = cloneValue(descriptor.value, seen);
|
|
74
|
-
}
|
|
75
|
-
Object.defineProperty(result, key, descriptor);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { deepClone };
|
package/dist/deep-equal.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
function deepEqual(a, b) {
|
|
2
|
-
if (a === b) return true;
|
|
3
|
-
if (a == null || b == null) return a === b;
|
|
4
|
-
const typeA = typeof a;
|
|
5
|
-
const typeB = typeof b;
|
|
6
|
-
if (typeA !== typeB) return false;
|
|
7
|
-
if (typeA !== 'object') return false;
|
|
8
|
-
if (a instanceof Date && b instanceof Date) {
|
|
9
|
-
return a.getTime() === b.getTime();
|
|
10
|
-
}
|
|
11
|
-
if (a instanceof RegExp && b instanceof RegExp) {
|
|
12
|
-
return a.source === b.source && a.flags === b.flags;
|
|
13
|
-
}
|
|
14
|
-
if (a instanceof Map && b instanceof Map) {
|
|
15
|
-
if (a.size !== b.size) return false;
|
|
16
|
-
for (const [key, value] of a) {
|
|
17
|
-
if (!b.has(key) || !deepEqual(value, b.get(key))) return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (a instanceof Set && b instanceof Set) {
|
|
22
|
-
if (a.size !== b.size) return false;
|
|
23
|
-
for (const value of a) {
|
|
24
|
-
if (!b.has(value)) return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(a)) {
|
|
29
|
-
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
30
|
-
return a.every((item, index) => deepEqual(item, b[index]));
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(b)) return false;
|
|
33
|
-
const objA = a;
|
|
34
|
-
const objB = b;
|
|
35
|
-
const keysA = Object.keys(objA);
|
|
36
|
-
const keysB = Object.keys(objB);
|
|
37
|
-
if (keysA.length !== keysB.length) return false;
|
|
38
|
-
return keysA.every(key => key in objB && deepEqual(objA[key], objB[key]));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { deepEqual };
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { isNodeAccessor } from '../../../lib/utils.js';
|
|
2
|
-
|
|
3
|
-
let updateQueue = [];
|
|
4
|
-
let isUpdating = false;
|
|
5
|
-
let flushTimeoutId;
|
|
6
|
-
let currentBatchingConfig = {};
|
|
7
|
-
function addToQueue(update, config = currentBatchingConfig) {
|
|
8
|
-
const maxSize = config.maxBatchSize ?? 100;
|
|
9
|
-
if (update.path) {
|
|
10
|
-
updateQueue = updateQueue.filter(existing => existing.path !== update.path);
|
|
11
|
-
}
|
|
12
|
-
updateQueue.push(update);
|
|
13
|
-
if (updateQueue.length > maxSize) {
|
|
14
|
-
flushUpdates();
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
scheduleFlush(config);
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
function scheduleFlush(config) {
|
|
21
|
-
if (flushTimeoutId !== undefined) {
|
|
22
|
-
clearTimeout(flushTimeoutId);
|
|
23
|
-
}
|
|
24
|
-
const delay = config.autoFlushDelay ?? 16;
|
|
25
|
-
flushTimeoutId = setTimeout(() => {
|
|
26
|
-
flushUpdates();
|
|
27
|
-
}, delay);
|
|
28
|
-
}
|
|
29
|
-
function flushUpdates() {
|
|
30
|
-
if (isUpdating) return;
|
|
31
|
-
let queue;
|
|
32
|
-
do {
|
|
33
|
-
if (updateQueue.length === 0) return;
|
|
34
|
-
isUpdating = true;
|
|
35
|
-
queue = updateQueue;
|
|
36
|
-
updateQueue = [];
|
|
37
|
-
if (flushTimeoutId !== undefined) {
|
|
38
|
-
clearTimeout(flushTimeoutId);
|
|
39
|
-
flushTimeoutId = undefined;
|
|
40
|
-
}
|
|
41
|
-
queue.sort((a, b) => (b.depth ?? 0) - (a.depth ?? 0));
|
|
42
|
-
try {
|
|
43
|
-
queue.forEach(({
|
|
44
|
-
fn
|
|
45
|
-
}) => fn());
|
|
46
|
-
} finally {
|
|
47
|
-
isUpdating = false;
|
|
48
|
-
}
|
|
49
|
-
} while (updateQueue.length > 0);
|
|
50
|
-
}
|
|
51
|
-
function batchUpdates(fn, path) {
|
|
52
|
-
const startTime = performance.now();
|
|
53
|
-
const depth = 0;
|
|
54
|
-
const update = {
|
|
55
|
-
fn,
|
|
56
|
-
startTime,
|
|
57
|
-
depth,
|
|
58
|
-
path
|
|
59
|
-
};
|
|
60
|
-
const wasFlushed = addToQueue(update, currentBatchingConfig);
|
|
61
|
-
if (!wasFlushed) {
|
|
62
|
-
const isTimedOut = currentBatchingConfig.batchTimeoutMs && updateQueue.length > 0 && startTime - updateQueue[0].startTime >= currentBatchingConfig.batchTimeoutMs;
|
|
63
|
-
if (isTimedOut) {
|
|
64
|
-
flushUpdates();
|
|
65
|
-
} else if (!isUpdating && updateQueue.length > 0) {
|
|
66
|
-
queueMicrotask(() => {
|
|
67
|
-
flushUpdates();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function withBatching(config = {}) {
|
|
73
|
-
const {
|
|
74
|
-
enabled = true
|
|
75
|
-
} = config;
|
|
76
|
-
currentBatchingConfig = {
|
|
77
|
-
...currentBatchingConfig,
|
|
78
|
-
...config
|
|
79
|
-
};
|
|
80
|
-
return tree => {
|
|
81
|
-
if (!enabled) {
|
|
82
|
-
return tree;
|
|
83
|
-
}
|
|
84
|
-
const originalTreeCall = tree.bind(tree);
|
|
85
|
-
const enhancedTree = function (...args) {
|
|
86
|
-
if (args.length === 0) {
|
|
87
|
-
return originalTreeCall();
|
|
88
|
-
} else {
|
|
89
|
-
batchUpdates(() => {
|
|
90
|
-
if (args.length === 1) {
|
|
91
|
-
const arg = args[0];
|
|
92
|
-
if (typeof arg === 'function') {
|
|
93
|
-
originalTreeCall(arg);
|
|
94
|
-
} else {
|
|
95
|
-
originalTreeCall(arg);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
Object.setPrototypeOf(enhancedTree, Object.getPrototypeOf(tree));
|
|
102
|
-
Object.assign(enhancedTree, tree);
|
|
103
|
-
if ('state' in tree) {
|
|
104
|
-
Object.defineProperty(enhancedTree, 'state', {
|
|
105
|
-
value: tree.state,
|
|
106
|
-
enumerable: false,
|
|
107
|
-
configurable: true
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if ('$' in tree) {
|
|
111
|
-
Object.defineProperty(enhancedTree, '$', {
|
|
112
|
-
value: tree['$'],
|
|
113
|
-
enumerable: false,
|
|
114
|
-
configurable: true
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
enhancedTree.batchUpdate = updater => {
|
|
118
|
-
batchUpdates(() => {
|
|
119
|
-
const current = originalTreeCall();
|
|
120
|
-
const updates = updater(current);
|
|
121
|
-
Object.entries(updates).forEach(([key, value]) => {
|
|
122
|
-
const property = enhancedTree.state[key];
|
|
123
|
-
if (property && 'set' in property) {
|
|
124
|
-
property.set(value);
|
|
125
|
-
} else if (isNodeAccessor(property)) {
|
|
126
|
-
property(value);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
return enhancedTree;
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function withHighPerformanceBatching() {
|
|
135
|
-
return withBatching({
|
|
136
|
-
enabled: true,
|
|
137
|
-
maxBatchSize: 200,
|
|
138
|
-
batchTimeoutMs: 0
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function flushBatchedUpdates() {
|
|
142
|
-
if (updateQueue.length > 0) {
|
|
143
|
-
const queue = updateQueue.slice();
|
|
144
|
-
updateQueue = [];
|
|
145
|
-
isUpdating = false;
|
|
146
|
-
queue.sort((a, b) => (b.depth ?? 0) - (a.depth ?? 0));
|
|
147
|
-
queue.forEach(({
|
|
148
|
-
fn
|
|
149
|
-
}) => {
|
|
150
|
-
fn();
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function hasPendingUpdates() {
|
|
155
|
-
return updateQueue.length > 0;
|
|
156
|
-
}
|
|
157
|
-
function getBatchQueueSize() {
|
|
158
|
-
return updateQueue.length;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export { flushBatchedUpdates, getBatchQueueSize, hasPendingUpdates, withBatching, withHighPerformanceBatching };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { computed } from '@angular/core';
|
|
2
|
-
import { createEnhancer } from '../../index.js';
|
|
3
|
-
|
|
4
|
-
function computedEnhancer(_config = {}) {
|
|
5
|
-
return createEnhancer({
|
|
6
|
-
name: 'computed',
|
|
7
|
-
provides: ['computed'],
|
|
8
|
-
requires: []
|
|
9
|
-
}, tree => {
|
|
10
|
-
const computedTree = tree;
|
|
11
|
-
computedTree.computed = function (computeFn) {
|
|
12
|
-
return computed(() => computeFn(tree.state));
|
|
13
|
-
};
|
|
14
|
-
return computedTree;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function createComputed(dependencies, computeFn) {
|
|
18
|
-
return computed(computeFn);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { computedEnhancer, createComputed };
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { signal } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
function createActivityTracker() {
|
|
4
|
-
const modules = new Map();
|
|
5
|
-
return {
|
|
6
|
-
trackMethodCall: (module, method, duration) => {
|
|
7
|
-
const existing = modules.get(module);
|
|
8
|
-
if (existing) {
|
|
9
|
-
existing.lastActivity = new Date();
|
|
10
|
-
existing.operationCount++;
|
|
11
|
-
existing.averageExecutionTime = (existing.averageExecutionTime * (existing.operationCount - 1) + duration) / existing.operationCount;
|
|
12
|
-
} else {
|
|
13
|
-
modules.set(module, {
|
|
14
|
-
name: module,
|
|
15
|
-
methods: [method],
|
|
16
|
-
addedAt: new Date(),
|
|
17
|
-
lastActivity: new Date(),
|
|
18
|
-
operationCount: 1,
|
|
19
|
-
averageExecutionTime: duration,
|
|
20
|
-
errorCount: 0
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
trackError: (module, error, context) => {
|
|
25
|
-
const existing = modules.get(module);
|
|
26
|
-
if (existing) {
|
|
27
|
-
existing.errorCount++;
|
|
28
|
-
}
|
|
29
|
-
console.error(`❌ [${module}] Error${context ? ` in ${context}` : ''}:`, error);
|
|
30
|
-
},
|
|
31
|
-
getModuleActivity: module => modules.get(module),
|
|
32
|
-
getAllModules: () => Array.from(modules.values())
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function createCompositionLogger() {
|
|
36
|
-
const logs = [];
|
|
37
|
-
const addLog = (module, type, data) => {
|
|
38
|
-
logs.push({
|
|
39
|
-
timestamp: new Date(),
|
|
40
|
-
module,
|
|
41
|
-
type,
|
|
42
|
-
data
|
|
43
|
-
});
|
|
44
|
-
if (logs.length > 1000) {
|
|
45
|
-
logs.splice(0, logs.length - 1000);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
logComposition: (modules, action) => {
|
|
50
|
-
addLog('core', 'composition', {
|
|
51
|
-
modules,
|
|
52
|
-
action
|
|
53
|
-
});
|
|
54
|
-
console.log(`🔗 Composition ${action}:`, modules.join(' → '));
|
|
55
|
-
},
|
|
56
|
-
logMethodExecution: (module, method, args, result) => {
|
|
57
|
-
addLog(module, 'method', {
|
|
58
|
-
method,
|
|
59
|
-
args,
|
|
60
|
-
result
|
|
61
|
-
});
|
|
62
|
-
console.debug(`🔧 [${module}] ${method}`, {
|
|
63
|
-
args,
|
|
64
|
-
result
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
logStateChange: (module, path, oldValue, newValue) => {
|
|
68
|
-
addLog(module, 'state', {
|
|
69
|
-
path,
|
|
70
|
-
oldValue,
|
|
71
|
-
newValue
|
|
72
|
-
});
|
|
73
|
-
console.debug(`📝 [${module}] State change at ${path}:`, {
|
|
74
|
-
from: oldValue,
|
|
75
|
-
to: newValue
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
logPerformanceWarning: (module, operation, duration, threshold) => {
|
|
79
|
-
addLog(module, 'performance', {
|
|
80
|
-
operation,
|
|
81
|
-
duration,
|
|
82
|
-
threshold
|
|
83
|
-
});
|
|
84
|
-
console.warn(`⚠️ [${module}] Slow ${operation}: ${duration.toFixed(2)}ms (threshold: ${threshold}ms)`);
|
|
85
|
-
},
|
|
86
|
-
exportLogs: () => [...logs]
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function createModularMetrics() {
|
|
90
|
-
const metricsSignal = signal({
|
|
91
|
-
totalUpdates: 0,
|
|
92
|
-
moduleUpdates: {},
|
|
93
|
-
modulePerformance: {},
|
|
94
|
-
compositionChain: [],
|
|
95
|
-
signalGrowth: {},
|
|
96
|
-
memoryDelta: {},
|
|
97
|
-
moduleCacheStats: {}
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
signal: metricsSignal.asReadonly(),
|
|
101
|
-
updateMetrics: updates => {
|
|
102
|
-
metricsSignal.update(current => ({
|
|
103
|
-
...current,
|
|
104
|
-
...updates
|
|
105
|
-
}));
|
|
106
|
-
},
|
|
107
|
-
trackModuleUpdate: (module, duration) => {
|
|
108
|
-
metricsSignal.update(current => ({
|
|
109
|
-
...current,
|
|
110
|
-
totalUpdates: current.totalUpdates + 1,
|
|
111
|
-
moduleUpdates: {
|
|
112
|
-
...current.moduleUpdates,
|
|
113
|
-
[module]: (current.moduleUpdates[module] || 0) + 1
|
|
114
|
-
},
|
|
115
|
-
modulePerformance: {
|
|
116
|
-
...current.modulePerformance,
|
|
117
|
-
[module]: duration
|
|
118
|
-
}
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function withDevTools(config = {}) {
|
|
124
|
-
const {
|
|
125
|
-
enabled = true,
|
|
126
|
-
treeName = 'ModularSignalTree',
|
|
127
|
-
enableBrowserDevTools = true,
|
|
128
|
-
enableLogging = true,
|
|
129
|
-
performanceThreshold = 16
|
|
130
|
-
} = config;
|
|
131
|
-
return tree => {
|
|
132
|
-
if (!enabled) {
|
|
133
|
-
const createNoopInterface = () => ({
|
|
134
|
-
activityTracker: {
|
|
135
|
-
trackMethodCall: () => undefined,
|
|
136
|
-
trackError: () => undefined,
|
|
137
|
-
getModuleActivity: () => undefined,
|
|
138
|
-
getAllModules: () => []
|
|
139
|
-
},
|
|
140
|
-
logger: {
|
|
141
|
-
logComposition: () => undefined,
|
|
142
|
-
logMethodExecution: () => undefined,
|
|
143
|
-
logStateChange: () => undefined,
|
|
144
|
-
logPerformanceWarning: () => undefined,
|
|
145
|
-
exportLogs: () => []
|
|
146
|
-
},
|
|
147
|
-
metrics: signal({
|
|
148
|
-
totalUpdates: 0,
|
|
149
|
-
moduleUpdates: {},
|
|
150
|
-
modulePerformance: {},
|
|
151
|
-
compositionChain: [],
|
|
152
|
-
signalGrowth: {},
|
|
153
|
-
memoryDelta: {},
|
|
154
|
-
moduleCacheStats: {}
|
|
155
|
-
}).asReadonly(),
|
|
156
|
-
trackComposition: () => undefined,
|
|
157
|
-
startModuleProfiling: () => '',
|
|
158
|
-
endModuleProfiling: () => undefined,
|
|
159
|
-
connectDevTools: () => undefined,
|
|
160
|
-
exportDebugSession: () => ({
|
|
161
|
-
metrics: {
|
|
162
|
-
totalUpdates: 0,
|
|
163
|
-
moduleUpdates: {},
|
|
164
|
-
modulePerformance: {},
|
|
165
|
-
compositionChain: [],
|
|
166
|
-
signalGrowth: {},
|
|
167
|
-
memoryDelta: {},
|
|
168
|
-
moduleCacheStats: {}
|
|
169
|
-
},
|
|
170
|
-
modules: [],
|
|
171
|
-
logs: [],
|
|
172
|
-
compositionHistory: []
|
|
173
|
-
})
|
|
174
|
-
});
|
|
175
|
-
return Object.assign(tree, {
|
|
176
|
-
__devTools: createNoopInterface()
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
const activityTracker = createActivityTracker();
|
|
180
|
-
const logger = enableLogging ? createCompositionLogger() : {
|
|
181
|
-
logComposition: () => undefined,
|
|
182
|
-
logMethodExecution: () => undefined,
|
|
183
|
-
logStateChange: () => undefined,
|
|
184
|
-
logPerformanceWarning: () => undefined,
|
|
185
|
-
exportLogs: () => []
|
|
186
|
-
};
|
|
187
|
-
const metrics = createModularMetrics();
|
|
188
|
-
const compositionHistory = [];
|
|
189
|
-
const activeProfiles = new Map();
|
|
190
|
-
let browserDevTools = null;
|
|
191
|
-
if (enableBrowserDevTools && typeof window !== 'undefined' && '__REDUX_DEVTOOLS_EXTENSION__' in window) {
|
|
192
|
-
const devToolsExt = window['__REDUX_DEVTOOLS_EXTENSION__'];
|
|
193
|
-
const connection = devToolsExt.connect({
|
|
194
|
-
name: treeName,
|
|
195
|
-
features: {
|
|
196
|
-
dispatch: true,
|
|
197
|
-
jump: true,
|
|
198
|
-
skip: true
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
browserDevTools = {
|
|
202
|
-
send: connection.send
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
const originalTreeCall = tree.bind(tree);
|
|
206
|
-
const enhancedTree = function (...args) {
|
|
207
|
-
if (args.length === 0) {
|
|
208
|
-
return originalTreeCall();
|
|
209
|
-
} else {
|
|
210
|
-
const startTime = performance.now();
|
|
211
|
-
let result;
|
|
212
|
-
if (args.length === 1) {
|
|
213
|
-
const arg = args[0];
|
|
214
|
-
if (typeof arg === 'function') {
|
|
215
|
-
result = originalTreeCall(arg);
|
|
216
|
-
} else {
|
|
217
|
-
result = originalTreeCall(arg);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const duration = performance.now() - startTime;
|
|
221
|
-
const newState = originalTreeCall();
|
|
222
|
-
metrics.trackModuleUpdate('core', duration);
|
|
223
|
-
if (duration > performanceThreshold) {
|
|
224
|
-
logger.logPerformanceWarning('core', 'update', duration, performanceThreshold);
|
|
225
|
-
}
|
|
226
|
-
if (browserDevTools) {
|
|
227
|
-
browserDevTools.send('UPDATE', newState);
|
|
228
|
-
}
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
Object.setPrototypeOf(enhancedTree, Object.getPrototypeOf(tree));
|
|
233
|
-
Object.assign(enhancedTree, tree);
|
|
234
|
-
if ('state' in tree) {
|
|
235
|
-
Object.defineProperty(enhancedTree, 'state', {
|
|
236
|
-
value: tree.state,
|
|
237
|
-
enumerable: false,
|
|
238
|
-
configurable: true
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
if ('$' in tree) {
|
|
242
|
-
Object.defineProperty(enhancedTree, '$', {
|
|
243
|
-
value: tree['$'],
|
|
244
|
-
enumerable: false,
|
|
245
|
-
configurable: true
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const devToolsInterface = {
|
|
249
|
-
activityTracker,
|
|
250
|
-
logger,
|
|
251
|
-
metrics: metrics.signal,
|
|
252
|
-
trackComposition: modules => {
|
|
253
|
-
compositionHistory.push({
|
|
254
|
-
timestamp: new Date(),
|
|
255
|
-
chain: [...modules]
|
|
256
|
-
});
|
|
257
|
-
metrics.updateMetrics({
|
|
258
|
-
compositionChain: modules
|
|
259
|
-
});
|
|
260
|
-
logger.logComposition(modules, 'with');
|
|
261
|
-
},
|
|
262
|
-
startModuleProfiling: module => {
|
|
263
|
-
const profileId = `${module}_${Date.now()}`;
|
|
264
|
-
activeProfiles.set(profileId, {
|
|
265
|
-
module,
|
|
266
|
-
operation: 'profile',
|
|
267
|
-
startTime: performance.now()
|
|
268
|
-
});
|
|
269
|
-
return profileId;
|
|
270
|
-
},
|
|
271
|
-
endModuleProfiling: profileId => {
|
|
272
|
-
const profile = activeProfiles.get(profileId);
|
|
273
|
-
if (profile) {
|
|
274
|
-
const duration = performance.now() - profile.startTime;
|
|
275
|
-
activityTracker.trackMethodCall(profile.module, profile.operation, duration);
|
|
276
|
-
activeProfiles.delete(profileId);
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
connectDevTools: name => {
|
|
280
|
-
if (browserDevTools) {
|
|
281
|
-
browserDevTools.send('@@INIT', originalTreeCall());
|
|
282
|
-
console.log(`🔗 Connected to Redux DevTools as "${name}"`);
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
exportDebugSession: () => ({
|
|
286
|
-
metrics: metrics.signal(),
|
|
287
|
-
modules: activityTracker.getAllModules(),
|
|
288
|
-
logs: logger.exportLogs(),
|
|
289
|
-
compositionHistory: [...compositionHistory]
|
|
290
|
-
})
|
|
291
|
-
};
|
|
292
|
-
return Object.assign(enhancedTree, {
|
|
293
|
-
__devTools: devToolsInterface
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function enableDevTools(treeName = 'SignalTree') {
|
|
298
|
-
return withDevTools({
|
|
299
|
-
treeName,
|
|
300
|
-
enabled: true
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
function withFullDevTools(treeName = 'SignalTree') {
|
|
304
|
-
return withDevTools({
|
|
305
|
-
treeName,
|
|
306
|
-
enabled: true,
|
|
307
|
-
enableBrowserDevTools: true,
|
|
308
|
-
enableLogging: true,
|
|
309
|
-
performanceThreshold: 10
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function withProductionDevTools() {
|
|
313
|
-
return withDevTools({
|
|
314
|
-
enabled: true,
|
|
315
|
-
enableBrowserDevTools: false,
|
|
316
|
-
enableLogging: false,
|
|
317
|
-
performanceThreshold: 50
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export { enableDevTools, withDevTools, withFullDevTools, withProductionDevTools };
|