@@ -104,9 +104,7 @@ export default class Backburner {
104
104
105
105
this . _platform = platform ;
106
106
107
- this . _boundRunExpiredTimers = ( ) => {
108
- this . _runExpiredTimers ( ) ;
109
- } ;
107
+ this . _boundRunExpiredTimers = this . _runExpiredTimers . bind ( this ) ;
110
108
111
109
this . _boundAutorunEnd = ( ) => {
112
110
this . _autorun = null ;
@@ -511,7 +509,7 @@ export default class Backburner {
511
509
}
512
510
513
511
public cancel ( timer ?) {
514
- if ( ! timer ) { return false ; }
512
+ if ( timer === undefined || timer === null ) { return false ; }
515
513
let timerType = typeof timer ;
516
514
517
515
if ( timerType === 'number' ) { // we're cancelling a throttle or debounce
@@ -578,18 +576,16 @@ export default class Backburner {
578
576
if ( this . _timers . length === 0 ) {
579
577
this . _timers . push ( executeAt , id , target , method , args , stack ) ;
580
578
this . _installTimerTimeout ( ) ;
581
- return id ;
582
- }
583
-
584
- // find position to insert
585
- let i = searchTimer ( executeAt , this . _timers ) ;
586
- this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
579
+ } else {
580
+ // find position to insert
581
+ let i = searchTimer ( executeAt , this . _timers ) ;
582
+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
587
583
588
- // we should be the new earliest timer if i == 0
589
- if ( i === 0 ) {
590
- this . _reinstallTimerTimeout ( ) ;
584
+ // we should be the new earliest timer if i == 0
585
+ if ( i === 0 ) {
586
+ this . _reinstallTimerTimeout ( ) ;
587
+ }
591
588
}
592
-
593
589
return id ;
594
590
}
595
591
@@ -641,10 +637,11 @@ export default class Backburner {
641
637
642
638
private _runExpiredTimers ( ) {
643
639
this . _timerTimeoutId = null ;
644
- if ( this . _timers . length === 0 ) { return ; }
645
- this . begin ( ) ;
646
- this . _scheduleExpiredTimers ( ) ;
647
- this . end ( ) ;
640
+ if ( this . _timers . length > 0 ) {
641
+ this . begin ( ) ;
642
+ this . _scheduleExpiredTimers ( ) ;
643
+ this . end ( ) ;
644
+ }
648
645
}
649
646
650
647
private _scheduleExpiredTimers ( ) {
@@ -656,15 +653,13 @@ export default class Backburner {
656
653
657
654
for ( ; i < l ; i += 6 ) {
658
655
let executeAt = timers [ i ] ;
659
- if ( executeAt <= n ) {
660
- let target = timers [ i + 2 ] ;
661
- let method = timers [ i + 3 ] ;
662
- let args = timers [ i + 4 ] ;
663
- let stack = timers [ i + 5 ] ;
664
- this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
665
- } else {
666
- break ;
667
- }
656
+ if ( executeAt > n ) { break ; }
657
+
658
+ let target = timers [ i + 2 ] ;
659
+ let method = timers [ i + 3 ] ;
660
+ let args = timers [ i + 4 ] ;
661
+ let stack = timers [ i + 5 ] ;
662
+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
668
663
}
669
664
670
665
timers . splice ( 0 , i ) ;
0 commit comments