@ -145,6 +145,12 @@ export class Batch {
* /
* /
# roots = [ ] ;
# roots = [ ] ;
/ * *
* Effects created while this batch was active .
* @ type { Effect [ ] }
* /
# new _effects = [ ] ;
/ * *
/ * *
* Deferred effects ( which run after async work has completed ) that are DIRTY
* Deferred effects ( which run after async work has completed ) that are DIRTY
* @ type { Set < Effect > }
* @ type { Set < Effect > }
@ -472,6 +478,13 @@ export class Batch {
batches . delete ( this ) ;
batches . delete ( this ) ;
}
}
/ * *
* @ param { Effect } effect
* /
register _created _effect ( effect ) {
this . # new _effects . push ( effect ) ;
}
# commit ( ) {
# commit ( ) {
// If there are other pending batches, they now need to be 'rebased' —
// If there are other pending batches, they now need to be 'rebased' —
// in other words, we re-run block/async effects with the newly
// in other words, we re-run block/async effects with the newly
@ -525,6 +538,25 @@ export class Batch {
mark _effects ( source , others , marked , checked ) ;
mark _effects ( source , others , marked , checked ) ;
}
}
checked = new Map ( ) ;
var current _unequal = [ ... batch . current . keys ( ) ] . filter ( ( c ) =>
this . current . has ( c ) ? /** @type {[any, boolean]} */ ( this . current . get ( c ) ) [ 0 ] !== c : true
) ;
for ( const effect of this . # new _effects ) {
if (
( effect . f & ( DESTROYED | INERT | EAGER _EFFECT ) ) === 0 &&
depends _on ( effect , current _unequal , checked )
) {
if ( ( effect . f & ( ASYNC | BLOCK _EFFECT ) ) !== 0 ) {
set _signal _status ( effect , DIRTY ) ;
batch . schedule ( effect ) ;
} else {
batch . # dirty _effects . add ( effect ) ;
}
}
}
// Only apply and traverse when we know we triggered async work with marking the effects
// Only apply and traverse when we know we triggered async work with marking the effects
if ( batch . # roots . length > 0 ) {
if ( batch . # roots . length > 0 ) {
batch . apply ( ) ;
batch . apply ( ) ;