@@ -158,9 +158,7 @@ export default class Backburner {
158
158
159
159
this . _platform = platform ;
160
160
161
- this . _boundRunExpiredTimers = ( ) => {
162
- this . _runExpiredTimers ( ) ;
163
- } ;
161
+ this . _boundRunExpiredTimers = this . _runExpiredTimers . bind ( this ) ;
164
162
165
163
this . _boundAutorunEnd = ( ) => {
166
164
autorunsCompletedCount ++ ;
@@ -586,9 +584,10 @@ export default class Backburner {
586
584
587
585
public cancel ( timer ?) {
588
586
cancelCount ++ ;
589
- if ( ! timer ) { return false ; }
587
+
588
+ if ( timer === undefined || timer === null ) { return false ; }
589
+
590
590
let timerType = typeof timer ;
591
-
592
591
if ( timerType === 'number' ) { // we're cancelling a throttle or debounce
593
592
return this . _cancelItem ( timer , this . _throttlers ) || this . _cancelItem ( timer , this . _debouncees ) ;
594
593
} else if ( timerType === 'string' ) { // we're cancelling a setTimeout
@@ -653,18 +652,16 @@ export default class Backburner {
653
652
if ( this . _timers . length === 0 ) {
654
653
this . _timers . push ( executeAt , id , target , method , args , stack ) ;
655
654
this . _installTimerTimeout ( ) ;
656
- return id ;
657
- }
658
-
659
- // find position to insert
660
- let i = searchTimer ( executeAt , this . _timers ) ;
661
- this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
655
+ } else {
656
+ // find position to insert
657
+ let i = searchTimer ( executeAt , this . _timers ) ;
658
+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
662
659
663
- // we should be the new earliest timer if i == 0
664
- if ( i === 0 ) {
665
- this . _reinstallTimerTimeout ( ) ;
660
+ // we should be the new earliest timer if i == 0
661
+ if ( i === 0 ) {
662
+ this . _reinstallTimerTimeout ( ) ;
663
+ }
666
664
}
667
-
668
665
return id ;
669
666
}
670
667
@@ -716,10 +713,11 @@ export default class Backburner {
716
713
717
714
private _runExpiredTimers ( ) {
718
715
this . _timerTimeoutId = null ;
719
- if ( this . _timers . length === 0 ) { return ; }
720
- this . begin ( ) ;
721
- this . _scheduleExpiredTimers ( ) ;
722
- this . end ( ) ;
716
+ if ( this . _timers . length > 0 ) {
717
+ this . begin ( ) ;
718
+ this . _scheduleExpiredTimers ( ) ;
719
+ this . end ( ) ;
720
+ }
723
721
}
724
722
725
723
private _scheduleExpiredTimers ( ) {
@@ -731,15 +729,13 @@ export default class Backburner {
731
729
732
730
for ( ; i < l ; i += 6 ) {
733
731
let executeAt = timers [ i ] ;
734
- if ( executeAt <= n ) {
735
- let target = timers [ i + 2 ] ;
736
- let method = timers [ i + 3 ] ;
737
- let args = timers [ i + 4 ] ;
738
- let stack = timers [ i + 5 ] ;
739
- this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
740
- } else {
741
- break ;
742
- }
732
+ if ( executeAt > n ) { break ; }
733
+
734
+ let target = timers [ i + 2 ] ;
735
+ let method = timers [ i + 3 ] ;
736
+ let args = timers [ i + 4 ] ;
737
+ let stack = timers [ i + 5 ] ;
738
+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
743
739
}
744
740
745
741
timers . splice ( 0 , i ) ;
0 commit comments