@creact-labs/creact 0.2.5 → 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/LICENSE +1 -1
- package/dist/primitives/instance.js +35 -6
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -197,7 +197,7 @@ APPENDIX: How to apply the Apache License to your work.
|
|
|
197
197
|
same "printed page" as the copyright notice for easier
|
|
198
198
|
identification within third-party archives.
|
|
199
199
|
|
|
200
|
-
Copyright 2025 Daniel Coutinho Ribeiro
|
|
200
|
+
Copyright 2025 Daniel Coutinho Ribeiro <dcoutinho.96@gmail.com>
|
|
201
201
|
|
|
202
202
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
203
203
|
you may not use this file except in compliance with the License.
|
|
@@ -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)
|
|
@@ -111,8 +131,11 @@ export function useInstance(construct, props) {
|
|
|
111
131
|
this.outputSignals.set(key, createSignal(value));
|
|
112
132
|
}
|
|
113
133
|
else {
|
|
114
|
-
const [, write] = this.outputSignals.get(key);
|
|
115
|
-
|
|
134
|
+
const [read, write] = this.outputSignals.get(key);
|
|
135
|
+
// Only update if value actually changed
|
|
136
|
+
if (!shallowEqual(read(), value)) {
|
|
137
|
+
write(value);
|
|
138
|
+
}
|
|
116
139
|
}
|
|
117
140
|
}
|
|
118
141
|
});
|
|
@@ -134,8 +157,11 @@ export function useInstance(construct, props) {
|
|
|
134
157
|
node.outputSignals.set(key, createSignal(value));
|
|
135
158
|
}
|
|
136
159
|
else {
|
|
137
|
-
const [, write] = node.outputSignals.get(key);
|
|
138
|
-
|
|
160
|
+
const [read, write] = node.outputSignals.get(key);
|
|
161
|
+
// Only update if value actually changed
|
|
162
|
+
if (!shallowEqual(read(), value)) {
|
|
163
|
+
write(value);
|
|
164
|
+
}
|
|
139
165
|
}
|
|
140
166
|
}
|
|
141
167
|
}
|
|
@@ -195,8 +221,11 @@ export function fillInstanceOutputs(nodeId, outputs) {
|
|
|
195
221
|
batch(() => {
|
|
196
222
|
for (const [key, value] of Object.entries(outputs)) {
|
|
197
223
|
if (node.outputSignals.has(key)) {
|
|
198
|
-
const [, write] = node.outputSignals.get(key);
|
|
199
|
-
|
|
224
|
+
const [read, write] = node.outputSignals.get(key);
|
|
225
|
+
// Only update if value actually changed
|
|
226
|
+
if (!shallowEqual(read(), value)) {
|
|
227
|
+
write(value);
|
|
228
|
+
}
|
|
200
229
|
}
|
|
201
230
|
else {
|
|
202
231
|
node.outputSignals.set(key, createSignal(value));
|