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) {
2222}
2323
2424export 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 = [ ] ;
You can’t perform that action at this time.
0 commit comments