@@ -690,16 +690,6 @@ angular.module('ui.scroll', [])
690
690
return adjustBuffer ( ridActual ) ;
691
691
}
692
692
693
- function enqueueFetch ( rid , direction ) {
694
- if ( ! adapter . isLoading ) {
695
- adapter . loading ( true ) ;
696
- }
697
-
698
- if ( pending . push ( direction ) === 1 ) {
699
- return fetch ( rid ) ;
700
- }
701
- }
702
-
703
693
function isElementVisible ( wrapper ) {
704
694
return wrapper . element . height ( ) && wrapper . element [ 0 ] . offsetParent ;
705
695
}
@@ -790,16 +780,31 @@ angular.module('ui.scroll', [])
790
780
return keepFetching ;
791
781
}
792
782
783
+ function enqueueFetch ( rid , keepFetching ) {
784
+ if ( viewport . shouldLoadBottom ( ) && keepFetching ) {
785
+ // keepFetching = true means that at least one item app/prepended in the last batch had height > 0
786
+ if ( pending . push ( true ) === 1 ) {
787
+ fetch ( rid ) ;
788
+ adapter . loading ( true ) ;
789
+ }
790
+
791
+ } else if ( viewport . shouldLoadTop ( ) && ( keepFetching || pending [ 0 ] ) ) {
792
+ // pending[0] = true means that previous fetch was appending. We need to force at least one prepend
793
+ // BTW there will always be at least 1 element in the pending array because bottom is fetched first
794
+ if ( pending . push ( false ) === 1 ) {
795
+ fetch ( rid ) ;
796
+ adapter . loading ( true ) ;
797
+ }
798
+ }
799
+
800
+ }
801
+
793
802
function adjustBuffer ( rid ) {
794
803
// We need the item bindings to be processed before we can do adjustment
795
804
return $timeout ( ( ) => {
796
805
processBufferedItems ( rid ) ;
797
806
798
- if ( viewport . shouldLoadBottom ( ) ) {
799
- enqueueFetch ( rid , true ) ;
800
- } else if ( viewport . shouldLoadTop ( ) ) {
801
- enqueueFetch ( rid , false ) ;
802
- }
807
+ enqueueFetch ( rid , true ) ;
803
808
804
809
if ( ! pending . length ) {
805
810
return adapter . calculateProperties ( ) ;
@@ -810,17 +815,8 @@ angular.module('ui.scroll', [])
810
815
function adjustBufferAfterFetch ( rid ) {
811
816
// We need the item bindings to be processed before we can do adjustment
812
817
return $timeout ( ( ) => {
813
- let keepFetching = processBufferedItems ( rid ) ;
814
-
815
- if ( viewport . shouldLoadBottom ( ) && keepFetching ) {
816
- // keepFetching = true means that at least one item app/prepended in the last batch had height > 0
817
- enqueueFetch ( rid , true ) ;
818
- } else if ( viewport . shouldLoadTop ( ) && ( keepFetching || pending [ 0 ] ) ) {
819
- // pending[0] = true means that previous fetch was appending. We need to force at least one prepend
820
- // BTW there will always be at least 1 element in the pending array because bottom is fetched first
821
- enqueueFetch ( rid , false ) ;
822
- }
823
818
819
+ enqueueFetch ( rid , processBufferedItems ( rid ) ) ;
824
820
pending . shift ( ) ;
825
821
826
822
if ( ! pending . length ) {
@@ -890,11 +886,8 @@ angular.module('ui.scroll', [])
890
886
891
887
function resizeAndScrollHandler ( ) {
892
888
if ( ! $rootScope . $$phase && ! adapter . isLoading ) {
893
- if ( viewport . shouldLoadBottom ( ) ) {
894
- enqueueFetch ( ridActual , true ) ;
895
- } else if ( viewport . shouldLoadTop ( ) ) {
896
- enqueueFetch ( ridActual , false ) ;
897
- }
889
+
890
+ enqueueFetch ( ridActual , true ) ;
898
891
899
892
if ( pending . length ) {
900
893
unbindEvents ( ) ;
0 commit comments