@@ -193,15 +193,15 @@ export class Batch {
193
193
// if we didn't start any new async work, and no async work
194
194
// is outstanding from a previous flush, commit
195
195
if ( this . #async_effects. length === 0 && this . #pending === 0 ) {
196
+ this . #commit( ) ;
197
+
196
198
var render_effects = this . #render_effects;
197
199
var effects = this . #effects;
198
200
199
201
this . #render_effects = [ ] ;
200
202
this . #effects = [ ] ;
201
203
this . #block_effects = [ ] ;
202
204
203
- this . #commit( ) ;
204
-
205
205
flush_queued_effects ( render_effects ) ;
206
206
flush_queued_effects ( effects ) ;
207
207
@@ -539,43 +539,43 @@ function flush_queued_effects(effects) {
539
539
var length = effects . length ;
540
540
if ( length === 0 ) return ;
541
541
542
- for ( var i = 0 ; i < length ; i ++ ) {
543
- var effect = effects [ i ] ;
544
-
545
- if ( ( effect . f & ( DESTROYED | INERT ) ) === 0 ) {
546
- if ( is_dirty ( effect ) ) {
547
- var wv = write_version ;
548
-
549
- update_effect ( effect ) ;
550
-
551
- // Effects with no dependencies or teardown do not get added to the effect tree.
552
- // Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
553
- // don't know if we need to keep them until they are executed. Doing the check
554
- // here (rather than in `update_effect`) allows us to skip the work for
555
- // immediate effects.
556
- if ( effect . deps === null && effect . first === null && effect . nodes_start === null ) {
557
- // if there's no teardown or abort controller we completely unlink
558
- // the effect from the graph
559
- if ( effect . teardown === null && effect . ac === null ) {
560
- // remove this effect from the graph
561
- unlink_effect ( effect ) ;
562
- } else {
563
- // keep the effect in the graph, but free up some memory
564
- effect . fn = null ;
565
- }
566
- }
542
+ var i = 0 ;
567
543
568
- // if state is written in a user effect, abort and re-schedule, lest we run
569
- // effects that should be removed as a result of the state change
570
- if ( write_version > wv && ( effect . f & USER_EFFECT ) !== 0 ) {
571
- break ;
544
+ while ( i < length ) {
545
+ var effect = effects [ i ++ ] ;
546
+
547
+ if ( ( effect . f & ( DESTROYED | INERT ) ) === 0 && is_dirty ( effect ) ) {
548
+ var wv = write_version ;
549
+
550
+ update_effect ( effect ) ;
551
+
552
+ // Effects with no dependencies or teardown do not get added to the effect tree.
553
+ // Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
554
+ // don't know if we need to keep them until they are executed. Doing the check
555
+ // here (rather than in `update_effect`) allows us to skip the work for
556
+ // immediate effects.
557
+ if ( effect . deps === null && effect . first === null && effect . nodes_start === null ) {
558
+ // if there's no teardown or abort controller we completely unlink
559
+ // the effect from the graph
560
+ if ( effect . teardown === null && effect . ac === null ) {
561
+ // remove this effect from the graph
562
+ unlink_effect ( effect ) ;
563
+ } else {
564
+ // keep the effect in the graph, but free up some memory
565
+ effect . fn = null ;
572
566
}
573
567
}
568
+
569
+ // if state is written in a user effect, abort and re-schedule, lest we run
570
+ // effects that should be removed as a result of the state change
571
+ if ( write_version > wv && ( effect . f & USER_EFFECT ) !== 0 ) {
572
+ break ;
573
+ }
574
574
}
575
575
}
576
576
577
- for ( ; i < length ; i += 1 ) {
578
- schedule_effect ( effects [ i ] ) ;
577
+ while ( i < length ) {
578
+ schedule_effect ( effects [ i ++ ] ) ;
579
579
}
580
580
}
581
581
0 commit comments