11const tasks = new Set ( )
22let isStopped = false
33
4- export function add ( task ) {
4+ export function add ( task ) {
55 if ( isStopped ) {
66 tasks . add ( task )
77 } else {
88 runTask ( task )
99 }
1010}
1111
12- export function remove ( task ) {
12+ export function remove ( task ) {
1313 tasks . delete ( task )
1414}
1515
1616// this replaces the passed function with a function
1717// that batches all of its callback arguments
18- function batch ( fn ) {
19- return function batchingCallbacks ( ...args ) {
18+ function batch ( fn ) {
19+ return function batchingCallbacks ( ...args ) {
2020 const batchedArgs = args . map (
2121 arg =>
2222 typeof arg === 'function'
23- ? function batchedCallback ( ) {
24- try {
25- isStopped = true
26- return arg . apply ( this , arguments )
27- } finally {
28- tasks . forEach ( runTask )
29- tasks . clear ( )
30- isStopped = false
31- }
23+ ? function batchedCallback ( ) {
24+ try {
25+ isStopped = true
26+ return arg . apply ( this , arguments )
27+ } finally {
28+ tasks . forEach ( runTask )
29+ tasks . clear ( )
30+ isStopped = false
3231 }
32+ }
3333 : arg
3434 )
3535 return fn . apply ( this , batchedArgs )
3636 }
3737}
3838
39- function runTask ( task ) {
39+ function runTask ( task ) {
4040 task ( )
4141}
4242
@@ -55,9 +55,9 @@ if (globalObj) {
5555 globalObj . setTimeout = batch ( globalObj . setTimeout )
5656 globalObj . setInterval = batch ( globalObj . setInterval )
5757 // eslint-disable-next-line
58- Promise . prototype . then = batch ( Promise . prototype . then )
58+ Promise . prototype . then = batch ( Promise . prototype . then ) ;
5959 // eslint-disable-next-line
60- Promise . prototype . catch = batch ( Promise . prototype . catch )
60+ Promise . prototype . catch = batch ( Promise . prototype . catch ) ;
6161}
6262
6363// DOM event handlers and HTTP event handlers don't have to be batched
0 commit comments