Skip to content

Commit 7c839c2

Browse files
committed
A fix for the performance problem?
1 parent 727cd0c commit 7c839c2

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/ui-scroll.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,21 @@ angular.module('ui.scroll', [])
568568
adapter.reload = reload;
569569

570570
// events and bindings
571-
viewport.bind('resize', resizeAndScrollHandler);
572-
viewport.bind('scroll', resizeAndScrollHandler);
571+
function bindEvents() {
572+
viewport.bind('resize', resizeAndScrollHandler);
573+
viewport.bind('scroll', resizeAndScrollHandler);
574+
}
573575
viewport.bind('mousewheel', wheelHandler);
574576

577+
function unbindEvents() {
578+
viewport.unbind('resize', resizeAndScrollHandler);
579+
viewport.unbind('scroll', resizeAndScrollHandler);
580+
}
581+
575582
$scope.$on('$destroy', () => {
576583
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
577584
buffer.clear();
578-
viewport.unbind('resize', resizeAndScrollHandler);
579-
viewport.unbind('scroll', resizeAndScrollHandler);
585+
unbindEvents();
580586
viewport.unbind('mousewheel', wheelHandler);
581587
});
582588

@@ -738,7 +744,9 @@ angular.module('ui.scroll', [])
738744
enqueueFetch(rid, false);
739745
}
740746

741-
if (!pending.length) {
747+
if (pending.length) {
748+
// unbindEvents();
749+
} else {
742750
return adapter.calculateProperties();
743751
}
744752
});
@@ -763,6 +771,7 @@ angular.module('ui.scroll', [])
763771

764772
if (!pending.length) {
765773
adapter.loading(false);
774+
bindEvents();
766775
return adapter.calculateProperties();
767776
}
768777

@@ -828,7 +837,15 @@ angular.module('ui.scroll', [])
828837
function resizeAndScrollHandler() {
829838
if (!$rootScope.$$phase && !adapter.isLoading) {
830839
adapter.sCount++;
831-
adjustBuffer();
840+
if (viewport.shouldLoadBottom()) {
841+
enqueueFetch(ridActual, true);
842+
} else if (viewport.shouldLoadTop()) {
843+
enqueueFetch(ridActual, false);
844+
}
845+
846+
if (pending.length) {
847+
unbindEvents();
848+
}
832849
}
833850
}
834851

0 commit comments

Comments
 (0)