Skip to content

Commit 4144706

Browse files
committed
reuse arg index
1 parent c60436b commit 4144706

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Timer = string | number;
2424
const noop = function() {};
2525

2626
const SET_TIMEOUT = setTimeout;
27-
const DISABLE_SCHEDULE = {};
27+
const DISABLE_SCHEDULE = Object.freeze([]);
2828

2929
function parseArgs(...args: any[]);
3030
function parseArgs() {
@@ -453,16 +453,16 @@ export default class Backburner {
453453
let index = findTimerItem(target, method, this._timers);
454454
let timerId;
455455
if (index === -1) {
456-
wait = parseInt(wait, 10);
457456
timerId = this._later(target, method, isImmediate ? DISABLE_SCHEDULE : args, wait);
458457

459458
if (isImmediate) {
460459
this._join(target, method, args);
461460
}
462461
} else {
463462
timerId = this._timers[index + 1];
464-
if (this._timers[index + 4] !== DISABLE_SCHEDULE) {
465-
this._timers[index + 4] = args;
463+
let argIndex = index + 4;
464+
if (this._timers[argIndex] !== DISABLE_SCHEDULE) {
465+
this._timers[argIndex] = args;
466466
}
467467
}
468468

@@ -491,6 +491,7 @@ export default class Backburner {
491491
let [target, method, args, wait, isImmediate = false] = parseDebounceArgs(...arguments);
492492

493493
let index = findTimerItem(target, method, this._timers);
494+
494495
let timerId;
495496
if (index === -1) {
496497
timerId = this._later(target, method, isImmediate ? DISABLE_SCHEDULE : args, wait);
@@ -501,11 +502,12 @@ export default class Backburner {
501502
let executeAt = this._platform.now() + wait || this._timers[index];
502503
this._timers[index] = executeAt;
503504

504-
if (this._timers[index + 4] !== DISABLE_SCHEDULE) {
505-
this._timers[index + 4] = args;
505+
let argIndex = index + 4;
506+
if (this._timers[argIndex] !== DISABLE_SCHEDULE) {
507+
this._timers[argIndex] = args;
506508
}
507-
508509
timerId = this._timers[index + 1];
510+
509511
if (index === 0) {
510512
this._reinstallTimerTimeout();
511513
}
@@ -618,7 +620,7 @@ export default class Backburner {
618620
}
619621
}
620622

621-
private _later(target, method, args, wait, isImmediate = false) {
623+
private _later(target, method, args, wait) {
622624
let stack = this.DEBUG ? new Error() : undefined;
623625
let executeAt = this._platform.now() + wait;
624626
let id = UUID++;
@@ -642,8 +644,7 @@ export default class Backburner {
642644
private _cancelLaterTimer(timer) {
643645
for (let i = 1; i < this._timers.length; i += 6) {
644646
if (this._timers[i] === timer) {
645-
i = i - 1;
646-
this._timers.splice(i, 6);
647+
this._timers.splice(i - 1, 6);
647648
if (i === 0) {
648649
this._reinstallTimerTimeout();
649650
}

0 commit comments

Comments
 (0)