@@ -39,8 +39,11 @@ export function proxy(value, onchange) {
3939 }
4040
4141 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+
4447 return value ;
4548 }
4649
@@ -144,7 +147,7 @@ export function proxy(value, onchange) {
144147
145148 // when we delete a property if the source is a proxy we remove the current onchange from
146149 // 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 ) {
148151 s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchange , true ) ;
149152 }
150153
@@ -161,24 +164,15 @@ export function proxy(value, onchange) {
161164 }
162165
163166 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 ) => {
168168 // we either add or remove the passed in value
169169 // to the onchanges array or we set every source onchange
170170 // 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 ) ;
177174 } else {
178- onchange = value ;
179- for ( let [ , s ] of sources ) {
180- s . o = value ;
181- }
175+ onchanges ?. add ( value ) ;
182176 }
183177 } ;
184178 }
@@ -277,6 +271,7 @@ export function proxy(value, onchange) {
277271 var other_s = sources . get ( i + '' ) ;
278272 if ( other_s !== undefined ) {
279273 if (
274+ onchange &&
280275 typeof other_s . v === 'object' &&
281276 other_s . v !== null &&
282277 STATE_SYMBOL in other_s . v
@@ -309,11 +304,13 @@ export function proxy(value, onchange) {
309304 }
310305 } else {
311306 has = s . v !== UNINITIALIZED ;
307+
312308 // when we set a property if the source is a proxy we remove the current onchange from
313309 // 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 ) {
315311 s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchange , true ) ;
316312 }
313+
317314 set (
318315 s ,
319316 with_parent ( ( ) => proxy ( value , onchange ) )
0 commit comments