Skip to content

Commit 49eb179

Browse files
authored
Merge pull request #321 from bekzod/cleanup-index
general cleanup
2 parents 76cf7fe + 2b13593 commit 49eb179

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

lib/index.ts

+22-27
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ export default class Backburner {
104104

105105
this._platform = platform;
106106

107-
this._boundRunExpiredTimers = () => {
108-
this._runExpiredTimers();
109-
};
107+
this._boundRunExpiredTimers = this._runExpiredTimers.bind(this);
110108

111109
this._boundAutorunEnd = () => {
112110
this._autorun = null;
@@ -511,7 +509,7 @@ export default class Backburner {
511509
}
512510

513511
public cancel(timer?) {
514-
if (!timer) { return false; }
512+
if (timer === undefined || timer === null) { return false; }
515513
let timerType = typeof timer;
516514

517515
if (timerType === 'number') { // we're cancelling a throttle or debounce
@@ -578,18 +576,16 @@ export default class Backburner {
578576
if (this._timers.length === 0) {
579577
this._timers.push(executeAt, id, target, method, args, stack);
580578
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);
587583

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+
}
591588
}
592-
593589
return id;
594590
}
595591

@@ -641,10 +637,11 @@ export default class Backburner {
641637

642638
private _runExpiredTimers() {
643639
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+
}
648645
}
649646

650647
private _scheduleExpiredTimers() {
@@ -656,15 +653,13 @@ export default class Backburner {
656653

657654
for (; i < l; i += 6) {
658655
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);
668663
}
669664

670665
timers.splice(0, i);

0 commit comments

Comments
 (0)