@@ -39,8 +39,11 @@ export function proxy(value, onchange) {
39
39
}
40
40
41
41
if ( STATE_SYMBOL in value ) {
42
- // @ts -ignore
43
- value [ PROXY_ONCHANGE_SYMBOL ] ( onchange ) ;
42
+ if ( onchange ) {
43
+ // @ts -ignore
44
+ value [ PROXY_ONCHANGE_SYMBOL ] ( onchange ) ;
45
+ }
46
+
44
47
return value ;
45
48
}
46
49
@@ -144,7 +147,7 @@ export function proxy(value, onchange) {
144
147
145
148
// when we delete a property if the source is a proxy we remove the current onchange from
146
149
// the proxy `onchanges` so that it doesn't trigger it anymore
147
- if ( typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
150
+ if ( onchange && typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
148
151
s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchange , true ) ;
149
152
}
150
153
@@ -161,24 +164,15 @@ export function proxy(value, onchange) {
161
164
}
162
165
163
166
if ( prop === PROXY_ONCHANGE_SYMBOL ) {
164
- return (
165
- /** @type {(() => unknown) | undefined } */ value ,
166
- /** @type {boolean } */ remove
167
- ) => {
167
+ return ( /** @type {(() => unknown) } */ value , /** @type {boolean } */ remove ) => {
168
168
// we either add or remove the passed in value
169
169
// to the onchanges array or we set every source onchange
170
170
// to the passed in value (if it's undefined it will make the chain stop)
171
- if ( onchange != null && value ) {
172
- if ( remove ) {
173
- onchanges ?. delete ( value ) ;
174
- } else {
175
- onchanges ?. add ( value ) ;
176
- }
171
+ // if (onchange != null && value) {
172
+ if ( remove ) {
173
+ onchanges ?. delete ( value ) ;
177
174
} else {
178
- onchange = value ;
179
- for ( let [ , s ] of sources ) {
180
- s . o = value ;
181
- }
175
+ onchanges ?. add ( value ) ;
182
176
}
183
177
} ;
184
178
}
@@ -277,6 +271,7 @@ export function proxy(value, onchange) {
277
271
var other_s = sources . get ( i + '' ) ;
278
272
if ( other_s !== undefined ) {
279
273
if (
274
+ onchange &&
280
275
typeof other_s . v === 'object' &&
281
276
other_s . v !== null &&
282
277
STATE_SYMBOL in other_s . v
@@ -309,11 +304,13 @@ export function proxy(value, onchange) {
309
304
}
310
305
} else {
311
306
has = s . v !== UNINITIALIZED ;
307
+
312
308
// when we set a property if the source is a proxy we remove the current onchange from
313
309
// the proxy `onchanges` so that it doesn't trigger it anymore
314
- if ( typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
310
+ if ( onchange && typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
315
311
s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchange , true ) ;
316
312
}
313
+
317
314
set (
318
315
s ,
319
316
with_parent ( ( ) => proxy ( value , onchange ) )
0 commit comments