@creact-labs/creact 0.2.6 → 0.2.7
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/dist/primitives/instance.js +23 -3
- package/package.json +1 -1
|
@@ -4,6 +4,26 @@
|
|
|
4
4
|
import { createSignal } from '../reactive/signal';
|
|
5
5
|
import { batch } from '../reactive/tracking';
|
|
6
6
|
import { getCurrentFiber, getCurrentResourcePath, pushResourcePath } from '../runtime/render';
|
|
7
|
+
/**
|
|
8
|
+
* Shallow equality check for output deduplication
|
|
9
|
+
*/
|
|
10
|
+
function shallowEqual(a, b) {
|
|
11
|
+
if (a === b)
|
|
12
|
+
return true;
|
|
13
|
+
if (a == null || b == null)
|
|
14
|
+
return false;
|
|
15
|
+
if (typeof a !== 'object' || typeof b !== 'object')
|
|
16
|
+
return false;
|
|
17
|
+
const keysA = Object.keys(a);
|
|
18
|
+
const keysB = Object.keys(b);
|
|
19
|
+
if (keysA.length !== keysB.length)
|
|
20
|
+
return false;
|
|
21
|
+
for (const key of keysA) {
|
|
22
|
+
if (a[key] !== b[key])
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
7
27
|
// Registry of all instance nodes by ID
|
|
8
28
|
const nodeRegistry = new Map();
|
|
9
29
|
// Track which fiber owns each nodeId (to detect duplicate siblings)
|
|
@@ -113,7 +133,7 @@ export function useInstance(construct, props) {
|
|
|
113
133
|
else {
|
|
114
134
|
const [read, write] = this.outputSignals.get(key);
|
|
115
135
|
// Only update if value actually changed
|
|
116
|
-
if (read()
|
|
136
|
+
if (!shallowEqual(read(), value)) {
|
|
117
137
|
write(value);
|
|
118
138
|
}
|
|
119
139
|
}
|
|
@@ -139,7 +159,7 @@ export function useInstance(construct, props) {
|
|
|
139
159
|
else {
|
|
140
160
|
const [read, write] = node.outputSignals.get(key);
|
|
141
161
|
// Only update if value actually changed
|
|
142
|
-
if (read()
|
|
162
|
+
if (!shallowEqual(read(), value)) {
|
|
143
163
|
write(value);
|
|
144
164
|
}
|
|
145
165
|
}
|
|
@@ -203,7 +223,7 @@ export function fillInstanceOutputs(nodeId, outputs) {
|
|
|
203
223
|
if (node.outputSignals.has(key)) {
|
|
204
224
|
const [read, write] = node.outputSignals.get(key);
|
|
205
225
|
// Only update if value actually changed
|
|
206
|
-
if (read()
|
|
226
|
+
if (!shallowEqual(read(), value)) {
|
|
207
227
|
write(value);
|
|
208
228
|
}
|
|
209
229
|
}
|