File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -22,30 +22,29 @@ export function error(msg) {
22
22
}
23
23
24
24
export const throttleer = {
25
- timers : { } ,
25
+ timers : [ ] ,
26
26
caches : [ ] ,
27
27
throttle ( fn ) {
28
28
if ( this . caches . indexOf ( fn ) === - 1 ) {
29
- const fnIndex = this . caches . length ;
30
-
31
29
// cache current handler
32
30
this . caches . push ( fn ) ;
33
31
34
32
// save timer for current handler
35
- this . timers [ fnIndex ] = setTimeout ( ( ) => {
33
+ this . timers . push ( setTimeout ( ( ) => {
36
34
fn ( ) ;
37
35
38
36
// 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 ) ) ;
41
40
}
42
41
} ,
43
42
reset ( ) {
44
43
// 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 ) ;
48
46
} ) ;
47
+ this . timers . length = 0 ;
49
48
50
49
// empty caches
51
50
this . caches = [ ] ;
You can’t perform that action at this time.
0 commit comments