File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 67
67
isLoading: false ,
68
68
isComplete: false ,
69
69
isFirstLoad: true , // save the current loading whether it is the first loading
70
- debounceTimer: null ,
71
- debounceDuration: 50 ,
70
+ inThrottle: false ,
72
71
infiniteLoopChecked: false , // save the status of infinite loop check
73
72
infiniteLoopTimer: null ,
74
73
continuousCallTimes: 0 ,
109
108
default: ' bottom' ,
110
109
},
111
110
forceUseInfiniteWrapper: null ,
111
+ throttleLimit: {
112
+ type: Number ,
113
+ default: 50 ,
114
+ },
112
115
},
113
116
mounted () {
114
117
this .scrollParent = this .getScrollParent ();
115
118
116
119
this .scrollHandler = function scrollHandlerOriginal (ev ) {
117
120
if (! this .isLoading ) {
118
- clearTimeout (this .debounceTimer );
119
-
120
121
if (ev && ev .constructor === Event ) {
121
- this .debounceTimer = setTimeout (this .attemptLoad , this .debounceDuration );
122
+ if (! this .inThrottle ) {
123
+ this .inThrottle = true ;
124
+ this .attemptLoad ();
125
+ setTimeout (() => { this .inThrottle = false ; }, this .throttleLimit );
126
+ }
122
127
} else {
123
128
this .attemptLoad ();
124
129
}
160
165
this .isLoading = false ;
161
166
this .isComplete = false ;
162
167
this .isFirstLoad = true ;
168
+ this .inThrottle = false ;
163
169
this .scrollParent .addEventListener (' scroll' , this .scrollHandler );
164
170
setTimeout (this .scrollHandler , 1 );
165
171
});
Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ describe('vue-infinite-loading', () => {
404
404
vm . $mount ( '#app' ) ;
405
405
} ) ;
406
406
407
- it ( 'should debounce properly for the scroll event handler\n (use div as the container and wave dots spinner)' , ( done ) => {
407
+ it ( 'should throttle properly for the scroll event handler\n (use div as the container and wave dots spinner)' , ( done ) => {
408
408
vm = new Vue ( Object . assign ( { } , basicConfig , {
409
409
data : {
410
410
list : [ ...new Array ( 20 ) . join ( '1' ) . split ( '' ) ] ,
@@ -420,11 +420,11 @@ describe('vue-infinite-loading', () => {
420
420
continuesCall ( ( ) => {
421
421
scrollParent . scrollTop += 10 ;
422
422
} , 10 , ( ) => {
423
- expect ( spyFn ) . to . have . been . callCount ( 0 + alreadyCalledTimes ) ;
423
+ expect ( spyFn ) . to . have . been . callCount ( 1 + alreadyCalledTimes ) ;
424
424
setTimeout ( ( ) => {
425
425
expect ( spyFn ) . to . have . been . callCount ( 1 + alreadyCalledTimes ) ;
426
426
done ( ) ;
427
- } , this . $refs . infiniteLoading . debounceDuration + 10 ) ;
427
+ } , this . $refs . infiniteLoading . throttleLimit + 10 ) ;
428
428
} ) ;
429
429
} ,
430
430
} ) ) ;
You can’t perform that action at this time.
0 commit comments