Skip to content

Commit 3139b0b

Browse files
committed
fix: throttleer bug when using multiple ins with v-show (#204)
1 parent b799ca1 commit 3139b0b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/utils.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,29 @@ export function error(msg) {
2222
}
2323

2424
export const throttleer = {
25-
timers: {},
25+
timers: [],
2626
caches: [],
2727
throttle(fn) {
2828
if (this.caches.indexOf(fn) === -1) {
29-
const fnIndex = this.caches.length;
30-
3129
// cache current handler
3230
this.caches.push(fn);
3331

3432
// save timer for current handler
35-
this.timers[fnIndex] = setTimeout(() => {
33+
this.timers.push(setTimeout(() => {
3634
fn();
3735

3836
// empty cache and timer
39-
this.caches.splice(fnIndex, 1);
40-
}, config.system.throttleLimit);
37+
this.caches.splice(this.caches.indexOf(fn), 1);
38+
this.timers.shift();
39+
}, config.system.throttleLimit));
4140
}
4241
},
4342
reset() {
4443
// reset all timers
45-
Object.keys(this.timers).forEach((key) => {
46-
clearTimeout(this.timers[key]);
47-
delete this.timers[key];
44+
this.timers.forEach((timer) => {
45+
clearTimeout(timer);
4846
});
47+
this.timers.length = 0;
4948

5049
// empty caches
5150
this.caches = [];

0 commit comments

Comments
 (0)