@@ -280,59 +280,50 @@ export function create_proxy(value, onchanges) {
280280 batching = true ;
281281 }
282282
283- // if we are changing the length of the array we batch all the changes
284- // to the sources and the original value by calling batch_onchange and immediately
285- // invoking it...otherwise we just invoke an identity function
286- ( is_proxied_array && prop === 'length' ? batch_onchange : identity ) ( ( ) => {
287- // variable.length = value -> clear all signals with index >= value
288- if ( is_proxied_array && prop === 'length' ) {
289- for ( var i = value ; i < /** @type {Source<number> } */ ( s ) . v ; i += 1 ) {
290- var other_s = sources . get ( i + '' ) ;
291- if ( other_s !== undefined ) {
292- if (
293- typeof other_s . v === 'object' &&
294- other_s . v !== null &&
295- STATE_SYMBOL in other_s . v
296- ) {
297- other_s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchanges , true ) ;
298- }
299- set ( other_s , UNINITIALIZED ) ;
300- } else if ( i in target ) {
301- // If the item exists in the original, we need to create a uninitialized source,
302- // else a later read of the property would result in a source being created with
303- // the value of the original item at that index.
304- other_s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
305- sources . set ( i + '' , other_s ) ;
283+ // variable.length = value -> clear all signals with index >= value
284+ if ( is_proxied_array && prop === 'length' ) {
285+ for ( var i = value ; i < /** @type {Source<number> } */ ( s ) . v ; i += 1 ) {
286+ var other_s = sources . get ( i + '' ) ;
287+ if ( other_s !== undefined ) {
288+ if ( typeof other_s . v === 'object' && other_s . v !== null && STATE_SYMBOL in other_s . v ) {
289+ other_s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchanges , true ) ;
306290 }
291+ set ( other_s , UNINITIALIZED ) ;
292+ } else if ( i in target ) {
293+ // If the item exists in the original, we need to create a uninitialized source,
294+ // else a later read of the property would result in a source being created with
295+ // the value of the original item at that index.
296+ other_s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
297+ sources . set ( i + '' , other_s ) ;
307298 }
308299 }
300+ }
309301
310- // If we haven't yet created a source for this property, we need to ensure
311- // we do so otherwise if we read it later, then the write won't be tracked and
312- // the heuristics of effects will be different vs if we had read the proxied
313- // object property before writing to that property.
314- if ( s === undefined ) {
315- if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
316- s = with_parent ( ( ) => source ( undefined , stack ) ) ;
317- sources . set ( prop , s ) ;
318- }
319- } else {
320- has = s . v !== UNINITIALIZED ;
321-
322- // when we set a property if the source is a proxy we remove the parent `onchanges` from
323- // the child `onchanges` so that it doesn't trigger it anymore
324- if ( typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
325- s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchanges , true ) ;
326- }
302+ // If we haven't yet created a source for this property, we need to ensure
303+ // we do so otherwise if we read it later, then the write won't be tracked and
304+ // the heuristics of effects will be different vs if we had read the proxied
305+ // object property before writing to that property.
306+ if ( s === undefined ) {
307+ if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
308+ s = with_parent ( ( ) => source ( undefined , stack ) ) ;
309+ sources . set ( prop , s ) ;
327310 }
311+ } else {
312+ has = s . v !== UNINITIALIZED ;
328313
329- if ( s !== undefined ) {
330- set (
331- s ,
332- with_parent ( ( ) => create_proxy ( value , onchanges ) )
333- ) ;
314+ // when we set a property if the source is a proxy we remove the parent `onchanges` from
315+ // the child `onchanges` so that it doesn't trigger it anymore
316+ if ( typeof s . v === 'object' && s . v !== null && STATE_SYMBOL in s . v ) {
317+ s . v [ PROXY_ONCHANGE_SYMBOL ] ( onchanges , true ) ;
334318 }
335- } ) ( ) ;
319+ }
320+
321+ if ( s !== undefined ) {
322+ set (
323+ s ,
324+ with_parent ( ( ) => create_proxy ( value , onchanges ) )
325+ ) ;
326+ }
336327
337328 if ( is_proxied_array && prop === 'length' ) {
338329 batching = false ;
0 commit comments