@@ -16,7 +16,7 @@ interface Signal<T = any> extends ReactiveNode {
1616 pendingValue : T ;
1717}
1818
19- const queuedEffects : ( Effect | EffectScope | undefined ) [ ] = [ ] ;
19+ const queued : ( Effect | EffectScope | undefined ) [ ] = [ ] ;
2020const {
2121 link,
2222 unlink,
@@ -31,7 +31,28 @@ const {
3131 return updateSignal ( node as Signal ) ;
3232 }
3333 } ,
34- notify,
34+ notify ( effect : Effect | EffectScope ) {
35+ let flags = effect . flags ;
36+ let insertIndex = queuedLength ;
37+ let firstInsertedIndex = insertIndex ;
38+
39+ do {
40+ effect . flags = flags & ~ ( 2 satisfies ReactiveFlags . Watching ) | 64 /* Queued */ ;
41+ queued [ insertIndex ++ ] = effect ;
42+ effect = effect . subs ?. sub as Effect | EffectScope ;
43+ if ( effect === undefined || ( flags = effect . flags ) & 64 /* Queued */ ) {
44+ break ;
45+ }
46+ } while ( true ) ;
47+
48+ queuedLength = insertIndex ;
49+
50+ while ( firstInsertedIndex < insertIndex - 1 ) {
51+ const left = queued [ firstInsertedIndex ] ;
52+ queued [ firstInsertedIndex ++ ] = queued [ insertIndex - 1 ] ;
53+ queued [ -- insertIndex ] = left ;
54+ }
55+ } ,
3556 unwatched ( node : Signal | Computed | Effect | EffectScope ) {
3657 if ( ! ( node . flags & 1 satisfies ReactiveFlags . Mutable ) ) {
3758 effectScopeOper . call ( node ) ;
@@ -46,7 +67,7 @@ const {
4667let cycle = 0 ;
4768let batchDepth = 0 ;
4869let notifyIndex = 0 ;
49- let queuedEffectsLength = 0 ;
70+ let queuedLength = 0 ;
5071let activeSub : ReactiveNode | undefined ;
5172
5273export function getActiveSub ( ) : ReactiveNode | undefined {
@@ -183,19 +204,6 @@ function updateSignal(s: Signal): boolean {
183204 return s . currentValue !== ( s . currentValue = s . pendingValue ) ;
184205}
185206
186- function notify ( e : Effect | EffectScope ) {
187- const flags = e . flags ;
188- if ( ! ( flags & 64 /* Queued */ ) ) {
189- e . flags = flags | 64 /* Queued */ ;
190- const subs = e . subs ;
191- if ( subs !== undefined ) {
192- notify ( subs . sub as Effect | EffectScope ) ;
193- } else {
194- queuedEffects [ queuedEffectsLength ++ ] = e ;
195- }
196- }
197- }
198-
199207function run ( e : Effect | EffectScope , flags : ReactiveFlags ) : void {
200208 if (
201209 flags & 16 satisfies ReactiveFlags . Dirty
@@ -218,27 +226,17 @@ function run(e: Effect | EffectScope, flags: ReactiveFlags): void {
218226 e . flags &= ~ ( 4 satisfies ReactiveFlags . RecursedCheck ) ;
219227 purgeDeps ( e ) ;
220228 }
221- } else {
222- let link = e . deps ;
223- while ( link !== undefined ) {
224- const dep = link . dep ;
225- const depFlags = dep . flags ;
226- if ( depFlags & 64 /* Queued */ ) {
227- run ( dep , dep . flags = depFlags & ~ ( 64 /* Queued */ ) ) ;
228- }
229- link = link . nextDep ;
230- }
231229 }
232230}
233231
234232function flush ( ) : void {
235- while ( notifyIndex < queuedEffectsLength ) {
236- const effect = queuedEffects [ notifyIndex ] ! ;
237- queuedEffects [ notifyIndex ++ ] = undefined ;
233+ while ( notifyIndex < queuedLength ) {
234+ const effect = queued [ notifyIndex ] ! ;
235+ queued [ notifyIndex ++ ] = undefined ;
238236 run ( effect , effect . flags &= ~ ( 64 /* Queued */ ) ) ;
239237 }
240238 notifyIndex = 0 ;
241- queuedEffectsLength = 0 ;
239+ queuedLength = 0 ;
242240}
243241
244242function computedOper < T > ( this : Computed < T > ) : T {
0 commit comments