1- export interface IEffectScope extends Subscriber {
2- nextNotify : IEffectScope | undefined ;
1+ export interface IEffect extends Dependency , Subscriber {
2+ nextNotify : IEffect | undefined ;
33 notify ( ) : void ;
44}
55
6- export interface IEffect extends Dependency , IEffectScope { }
7-
86export interface IComputed extends Dependency , Subscriber {
97 update ( ) : void ;
108}
@@ -24,7 +22,7 @@ export interface Subscriber {
2422
2523export interface Link {
2624 dep : Dependency | IComputed | IEffect ;
27- sub : IComputed | IEffect | IEffectScope ;
25+ sub : IComputed | IEffect ;
2826 trackId : number ;
2927 // Also used as prev update
3028 prevSub : Link | undefined ;
@@ -43,13 +41,13 @@ export const enum DirtyLevels {
4341
4442export namespace System {
4543 export let activeSub : IComputed | IEffect | undefined = undefined ;
46- export let activeEffectScope : IEffectScope | undefined = undefined ;
44+ export let activeEffectScope : IEffect | undefined = undefined ;
4745 export let activeTrackId = 0 ;
4846 export let activeEffectScopeTrackId = 0 ;
4947 export let batchDepth = 0 ;
5048 export let lastTrackId = 0 ;
51- export let queuedEffects : IEffectScope | undefined = undefined ;
52- export let queuedEffectsTail : IEffectScope | undefined = undefined ;
49+ export let queuedEffects : IEffect | undefined = undefined ;
50+ export let queuedEffectsTail : IEffect | undefined = undefined ;
5351}
5452
5553export function startBatch ( ) {
@@ -75,7 +73,57 @@ export function endBatch() {
7573}
7674
7775export namespace Link {
78- export let pool : Link | undefined = undefined ;
76+ let pool : Link | undefined = undefined ;
77+
78+ export function get ( dep : Link [ 'dep' ] , sub : Link [ 'sub' ] , nextDep : Link | undefined ) {
79+ if ( pool !== undefined ) {
80+ const newLink = pool ;
81+ pool = newLink . nextDep ;
82+ newLink . nextDep = nextDep ;
83+ newLink . dep = dep ;
84+ newLink . sub = sub ;
85+ newLink . trackId = sub . trackId ;
86+ return newLink ;
87+ } else {
88+ return {
89+ dep,
90+ sub,
91+ trackId : sub . trackId ,
92+ nextDep : nextDep ,
93+ prevSub : undefined ,
94+ nextSub : undefined ,
95+ } ;
96+ }
97+ }
98+
99+ export function release ( link : Link ) {
100+ const dep = link . dep ;
101+ const nextSub = link . nextSub ;
102+ const prevSub = link . prevSub ;
103+
104+ if ( nextSub !== undefined ) {
105+ nextSub . prevSub = prevSub ;
106+ }
107+ if ( prevSub !== undefined ) {
108+ prevSub . nextSub = nextSub ;
109+ }
110+
111+ if ( nextSub === undefined ) {
112+ dep . subsTail = prevSub ;
113+ }
114+ if ( prevSub === undefined ) {
115+ dep . subs = nextSub ;
116+ }
117+
118+ // @ts -ignore
119+ link . dep = undefined ;
120+ // @ts -ignore
121+ link . sub = undefined ;
122+ link . prevSub = undefined ;
123+ link . nextSub = undefined ;
124+ link . nextDep = pool ;
125+ pool = link ;
126+ }
79127}
80128
81129export namespace Dependency {
@@ -89,25 +137,7 @@ export namespace Dependency {
89137 : sub . deps ;
90138
91139 if ( old === undefined || old . dep !== dep ) {
92- let newLink : Link ;
93-
94- if ( Link . pool !== undefined ) {
95- newLink = Link . pool ;
96- Link . pool = newLink . nextDep ;
97- newLink . nextDep = old ;
98- newLink . dep = dep ;
99- newLink . sub = sub ;
100- newLink . trackId = sub . trackId ;
101- } else {
102- newLink = {
103- dep,
104- sub,
105- trackId : sub . trackId ,
106- nextDep : old ,
107- prevSub : undefined ,
108- nextSub : undefined ,
109- } ;
110- }
140+ const newLink = Link . get ( dep , sub , old ) ;
111141
112142 if ( depsTail === undefined ) {
113143 sub . deps = newLink ;
@@ -401,52 +431,7 @@ export namespace Subscriber {
401431 sub . trackId = - sub . trackId ;
402432 }
403433
404- export function clearTrack ( link : Link ) {
405- do {
406- const nextDep = link . nextDep ;
407- const dep = link . dep ;
408- const nextSub = link . nextSub ;
409- const prevSub = link . prevSub ;
410-
411- if ( nextSub !== undefined ) {
412- nextSub . prevSub = prevSub ;
413- }
414- if ( prevSub !== undefined ) {
415- prevSub . nextSub = nextSub ;
416- }
417-
418- if ( nextSub === undefined ) {
419- dep . subsTail = prevSub ;
420- }
421- if ( prevSub === undefined ) {
422- dep . subs = nextSub ;
423- }
424-
425- // @ts -ignore
426- link . dep = undefined ;
427- // @ts -ignore
428- link . sub = undefined ;
429- link . prevSub = undefined ;
430- link . nextSub = undefined ;
431- link . nextDep = Link . pool ;
432- Link . pool = link ;
433-
434- if ( dep . subs === undefined && 'deps' in dep ) {
435- dep . dirtyLevel = DirtyLevels . Released ;
436- if ( dep . deps !== undefined ) {
437- link = dep . deps ;
438- dep . depsTail ! . nextDep = nextDep ;
439- dep . deps = undefined ;
440- dep . depsTail = undefined ;
441- continue ;
442- }
443- }
444-
445- link = nextDep ! ;
446- } while ( link !== undefined ) ;
447- }
448-
449- export function startTrackEffects ( sub : IEffectScope ) {
434+ export function startTrackEffects ( sub : IEffect ) {
450435 const newVersion = system . lastTrackId + 1 ;
451436 const prevSub = system . activeEffectScope ;
452437
@@ -461,7 +446,7 @@ export namespace Subscriber {
461446 return prevSub ;
462447 }
463448
464- export function endTrackEffects ( sub : IEffectScope , prevSub : IEffectScope | undefined ) {
449+ export function endTrackEffects ( sub : IEffect , prevSub : IEffect | undefined ) {
465450 if ( prevSub !== undefined ) {
466451 system . activeEffectScope = prevSub ;
467452 system . activeEffectScopeTrackId = prevSub . trackId ;
@@ -482,4 +467,23 @@ export namespace Subscriber {
482467 }
483468 sub . trackId = - sub . trackId ;
484469 }
470+
471+ export function clearTrack ( link : Link ) {
472+ do {
473+ const dep = link . dep ;
474+ const nextDep = link . nextDep ;
475+ Link . release ( link ) ;
476+ if ( dep . subs === undefined && 'deps' in dep ) {
477+ dep . dirtyLevel = DirtyLevels . Released ;
478+ if ( dep . deps !== undefined ) {
479+ link = dep . deps ;
480+ dep . depsTail ! . nextDep = nextDep ;
481+ dep . deps = undefined ;
482+ dep . depsTail = undefined ;
483+ continue ;
484+ }
485+ }
486+ link = nextDep ! ;
487+ } while ( link !== undefined ) ;
488+ }
485489}
0 commit comments