@@ -787,7 +787,6 @@ angular.module('ui.scroll', [])
787
787
fetch ( rid ) ;
788
788
adapter . loading ( true ) ;
789
789
}
790
-
791
790
} else if ( viewport . shouldLoadTop ( ) && ( keepFetching || pending [ 0 ] ) ) {
792
791
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend
793
792
// BTW there will always be at least 1 element in the pending array because bottom is fetched first
@@ -796,92 +795,87 @@ angular.module('ui.scroll', [])
796
795
adapter . loading ( true ) ;
797
796
}
798
797
}
799
-
800
798
}
801
799
802
800
function adjustBuffer ( rid ) {
803
801
// We need the item bindings to be processed before we can do adjustment
804
- return $timeout ( ( ) => {
805
- processBufferedItems ( rid ) ;
802
+ $timeout ( ( ) => {
806
803
804
+ processBufferedItems ( rid ) ;
807
805
enqueueFetch ( rid , true ) ;
808
806
809
807
if ( ! pending . length ) {
810
- return adapter . calculateProperties ( ) ;
808
+ adapter . calculateProperties ( ) ;
811
809
}
812
810
} ) ;
813
811
}
814
812
815
813
function adjustBufferAfterFetch ( rid ) {
816
814
// We need the item bindings to be processed before we can do adjustment
817
- return $timeout ( ( ) => {
815
+ $timeout ( ( ) => {
818
816
819
817
enqueueFetch ( rid , processBufferedItems ( rid ) ) ;
820
818
pending . shift ( ) ;
821
819
822
- if ( ! pending . length ) {
820
+ if ( pending . length )
821
+ fetch ( rid ) ;
822
+ else {
823
823
adapter . loading ( false ) ;
824
824
bindEvents ( ) ;
825
- return adapter . calculateProperties ( ) ;
825
+ adapter . calculateProperties ( ) ;
826
826
}
827
-
828
- return fetch ( rid ) ;
829
827
} ) ;
830
828
}
831
829
832
830
function fetch ( rid ) {
833
831
if ( pending [ 0 ] ) { // scrolling down
834
832
if ( buffer . length && ! viewport . shouldLoadBottom ( ) ) {
835
- return adjustBufferAfterFetch ( rid ) ;
836
- }
837
-
838
- return fetchNext ( ( result ) => {
839
- if ( ( rid && rid !== ridActual ) || $scope . $$destroyed ) {
840
- return ;
841
- }
842
-
843
- if ( result . length < bufferSize ) {
844
- buffer . eof = true ;
845
- // log 'eof is reached'
846
- }
847
-
848
- if ( result . length > 0 ) {
849
- viewport . clipTop ( ) ;
850
- buffer . append ( result ) ;
851
- }
852
-
853
- buffer . setUpper ( ) ;
854
-
855
- return adjustBufferAfterFetch ( rid ) ;
856
- } ) ;
857
- }
858
-
859
- // scrolling up
860
- if ( buffer . length && ! viewport . shouldLoadTop ( ) ) {
861
- return adjustBufferAfterFetch ( rid ) ;
862
- }
863
-
864
- return fetchPrevious ( ( result ) => {
865
- if ( ( rid && rid !== ridActual ) || $scope . $$destroyed ) {
866
- return ;
867
- }
868
-
869
- if ( result . length < bufferSize ) {
870
- buffer . bof = true ;
871
- // log 'bof is reached'
833
+ adjustBufferAfterFetch ( rid ) ;
834
+ } else {
835
+ fetchNext ( ( result ) => {
836
+ if ( ( rid && rid !== ridActual ) || $scope . $$destroyed ) {
837
+ return ;
838
+ }
839
+
840
+ if ( result . length < bufferSize ) {
841
+ buffer . eof = true ;
842
+ }
843
+
844
+ if ( result . length > 0 ) {
845
+ viewport . clipTop ( ) ;
846
+ buffer . append ( result ) ;
847
+ buffer . setUpper ( ) ;
848
+ }
849
+
850
+ adjustBufferAfterFetch ( rid ) ;
851
+ } ) ;
872
852
}
873
-
874
- if ( result . length > 0 ) {
875
- if ( buffer . length ) {
876
- viewport . clipBottom ( ) ;
877
- }
878
- buffer . prepend ( result ) ;
853
+ } else { // scrolling up
854
+ if ( buffer . length && ! viewport . shouldLoadTop ( ) ) {
855
+ adjustBufferAfterFetch ( rid ) ;
856
+ } else {
857
+ fetchPrevious ( ( result ) => {
858
+ if ( ( rid && rid !== ridActual ) || $scope . $$destroyed ) {
859
+ return ;
860
+ }
861
+
862
+ if ( result . length < bufferSize ) {
863
+ buffer . bof = true ;
864
+ // log 'bof is reached'
865
+ }
866
+
867
+ if ( result . length > 0 ) {
868
+ if ( buffer . length ) {
869
+ viewport . clipBottom ( ) ;
870
+ }
871
+ buffer . prepend ( result ) ;
872
+ buffer . setLower ( ) ;
873
+ }
874
+
875
+ adjustBufferAfterFetch ( rid ) ;
876
+ } ) ;
879
877
}
880
-
881
- buffer . setLower ( ) ;
882
-
883
- return adjustBufferAfterFetch ( rid ) ;
884
- } ) ;
878
+ }
885
879
}
886
880
887
881
function resizeAndScrollHandler ( ) {
0 commit comments