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 6767 isLoading: false ,
6868 isComplete: false ,
6969 isFirstLoad: true , // save the current loading whether it is the first loading
70- debounceTimer: null ,
71- debounceDuration: 50 ,
70+ inThrottle: false ,
7271 infiniteLoopChecked: false , // save the status of infinite loop check
7372 infiniteLoopTimer: null ,
7473 continuousCallTimes: 0 ,
109108 default: ' bottom' ,
110109 },
111110 forceUseInfiniteWrapper: null ,
111+ throttleLimit: {
112+ type: Number ,
113+ default: 50 ,
114+ },
112115 },
113116 mounted () {
114117 this .scrollParent = this .getScrollParent ();
115118
116119 this .scrollHandler = function scrollHandlerOriginal (ev ) {
117120 if (! this .isLoading ) {
118- clearTimeout (this .debounceTimer );
119-
120121 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+ }
122127 } else {
123128 this .attemptLoad ();
124129 }
160165 this .isLoading = false ;
161166 this .isComplete = false ;
162167 this .isFirstLoad = true ;
168+ this .inThrottle = false ;
163169 this .scrollParent .addEventListener (' scroll' , this .scrollHandler );
164170 setTimeout (this .scrollHandler , 1 );
165171 });
Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ describe('vue-infinite-loading', () => {
404404 vm . $mount ( '#app' ) ;
405405 } ) ;
406406
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 ) => {
408408 vm = new Vue ( Object . assign ( { } , basicConfig , {
409409 data : {
410410 list : [ ...new Array ( 20 ) . join ( '1' ) . split ( '' ) ] ,
@@ -420,11 +420,11 @@ describe('vue-infinite-loading', () => {
420420 continuesCall ( ( ) => {
421421 scrollParent . scrollTop += 10 ;
422422 } , 10 , ( ) => {
423- expect ( spyFn ) . to . have . been . callCount ( 0 + alreadyCalledTimes ) ;
423+ expect ( spyFn ) . to . have . been . callCount ( 1 + alreadyCalledTimes ) ;
424424 setTimeout ( ( ) => {
425425 expect ( spyFn ) . to . have . been . callCount ( 1 + alreadyCalledTimes ) ;
426426 done ( ) ;
427- } , this . $refs . infiniteLoading . debounceDuration + 10 ) ;
427+ } , this . $refs . infiniteLoading . throttleLimit + 10 ) ;
428428 } ) ;
429429 } ,
430430 } ) ) ;
You can’t perform that action at this time.
0 commit comments