File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 1- import { isInsideBatch } from './scheduler'
2-
31class Queue {
42 constructor ( ) {
53 this . taskSet = new Set ( )
4+ this . isInsideBatch = false
65 }
76
87 add = task => {
9- if ( isInsideBatch ) {
8+ if ( this . isInsideBatch ) {
109 this . taskSet . add ( task )
1110 } else {
1211 task ( )
@@ -19,6 +18,14 @@ class Queue {
1918 this . taskSet . clear ( )
2019 }
2120 } ;
21+
22+ on = ( ) => {
23+ this . isInsideBatch = true
24+ } ;
25+
26+ off = ( ) => {
27+ this . isInsideBatch = false
28+ } ;
2229}
2330
2431export const queue = new Queue ( )
Original file line number Diff line number Diff line change @@ -5,18 +5,17 @@ import { queue } from './queue'
55
66// this runs the passed function and delays all re-renders
77// until the function is finished running
8- export let isInsideBatch = false
98export function batch ( fn , ctx , args ) {
109 let result
11- if ( isInsideBatch ) {
10+ if ( queue . isInsideBatch ) {
1211 result = fn . apply ( ctx , args )
1312 } else {
1413 try {
15- isInsideBatch = true
14+ queue . on ( )
1615 result = fn . apply ( ctx , args )
1716 } finally {
1817 queue . flush ( )
19- isInsideBatch = false
18+ queue . off ( )
2019 }
2120 }
2221 return result
You can’t perform that action at this time.
0 commit comments