File tree Expand file tree Collapse file tree
packages/reactivity/src/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,12 +3,12 @@ export type Setter<T> = (val: T | ((val: T | null) => T)) => void;
33export type Signal < T > = [ Getter < T > , Setter < T > ] ;
44let OBSERVER : Computation < any > | null = null ;
55let BATCHING = false ;
6- const UPDATEQUEUE : Set < Computation < any > > = new Set ( ) ;
6+ const UPDATEQUEUE : Computation < any > [ ] = [ ] ;
77export class Computation < T > {
88 fn : ( ) => T ;
99 value : T | null = null ;
1010 state : number = 0 ;
11- dirty : boolean = false ;
11+ isQueued : boolean = false ;
1212 sources : Set < Computation < any > > = new Set ( ) ;
1313 observers : Set < Computation < any > > = new Set ( ) ;
1414 constructor ( fn : ( ) => T ) {
@@ -22,7 +22,7 @@ export class Computation<T> {
2222 }
2323 get = ( ) => {
2424 // We need to make sure memos update if they're accessed during a `batch`
25- if ( this . dirty ) {
25+ if ( this . isQueued ) {
2626 const prev = BATCHING ;
2727 BATCHING = false ;
2828 this . update ( ) ;
@@ -43,8 +43,9 @@ export class Computation<T> {
4343 }
4444 update ( ) {
4545 if ( BATCHING ) {
46- UPDATEQUEUE . add ( this ) ;
47- this . dirty = true ;
46+ if ( this . isQueued ) return ;
47+ UPDATEQUEUE . push ( this ) ;
48+ this . isQueued = true ;
4849 return ;
4950 }
5051 this . removeParentObservers ( ) ;
@@ -76,7 +77,7 @@ export class Computation<T> {
7677}
7778function stabilize ( ) {
7879 UPDATEQUEUE . forEach ( ( u ) => u . update ( ) ) ;
79- UPDATEQUEUE . clear ( ) ;
80+ UPDATEQUEUE . length = 0
8081}
8182export function batch < T > ( fn : ( ) => T ) {
8283 BATCHING = true ;
You can’t perform that action at this time.
0 commit comments