Skip to content

Commit fd7eadf

Browse files
committed
startIndex attribute
1 parent a9cd4d8 commit fd7eadf

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

src/ui-scroll.js

+15-37
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ angular.module('ui.scroll', [])
523523
const itemName = match[1];
524524
const datasourceName = match[2];
525525
const bufferSize = Math.max(3, +attr.bufferSize || 10);
526+
var startIndex = +attr.startIndex || 1;
526527

527528
return function link($scope, element, $attr, controllers, linker) {
528529
// starting from angular 1.2 compileLinker usage is deprecated
@@ -647,44 +648,29 @@ angular.module('ui.scroll', [])
647648

648649
adapter.reload = reload;
649650

650-
// events and bindings
651-
function bindEvents() {
652-
viewport.bind('resize', resizeAndScrollHandler);
653-
viewport.bind('scroll', resizeAndScrollHandler);
654-
}
655-
viewport.bind('mousewheel', wheelHandler);
656-
657-
function unbindEvents() {
658-
viewport.unbind('resize', resizeAndScrollHandler);
659-
viewport.unbind('scroll', resizeAndScrollHandler);
660-
}
661-
662651
$scope.$on('$destroy', () => {
663652
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
664653
buffer.clear();
665654
unbindEvents();
666655
viewport.unbind('mousewheel', wheelHandler);
667656
});
668657

669-
// update events (deprecated since v1.1.0, unsupported since 1.2.0)
670-
(() => {
671-
const eventListener = datasource.scope ? datasource.scope.$new() : $scope.$new();
672-
673-
eventListener.$on('insert.item', () => unsupportedMethod('insert'));
674-
675-
eventListener.$on('update.items', () => unsupportedMethod('update'));
676-
677-
eventListener.$on('delete.items', () => unsupportedMethod('delete'));
678-
679-
function unsupportedMethod(token) {
680-
throw new Error(token + ' event is no longer supported - use applyUpdates instead');
681-
}
682-
})();
658+
viewport.bind('mousewheel', wheelHandler);
683659

684660
reload();
685661

686662
/* Functions definitions */
687663

664+
function bindEvents() {
665+
viewport.bind('resize', resizeAndScrollHandler);
666+
viewport.bind('scroll', resizeAndScrollHandler);
667+
}
668+
669+
function unbindEvents() {
670+
viewport.unbind('resize', resizeAndScrollHandler);
671+
viewport.unbind('scroll', resizeAndScrollHandler);
672+
}
673+
688674
function dismissPendingRequests() {
689675
ridActual++;
690676
pending = [];
@@ -696,15 +682,10 @@ angular.module('ui.scroll', [])
696682
viewport.resetTopPadding();
697683
viewport.resetBottomPadding();
698684

699-
adapter.abCount = 0;
700-
adapter.abfCount = 0;
701-
adapter.sCount = 0;
685+
if (arguments.length)
686+
startIndex = arguments[0];
702687

703-
if (arguments.length) {
704-
buffer.clear(arguments[0]);
705-
} else {
706-
buffer.clear();
707-
}
688+
buffer.clear(startIndex);
708689

709690
return adjustBuffer(ridActual);
710691
}
@@ -812,7 +793,6 @@ angular.module('ui.scroll', [])
812793
function adjustBuffer(rid) {
813794
// We need the item bindings to be processed before we can do adjustment
814795
return $timeout(() => {
815-
adapter.abCount++;
816796
processBufferedItems(rid);
817797

818798
if (viewport.shouldLoadBottom()) {
@@ -830,7 +810,6 @@ angular.module('ui.scroll', [])
830810
function adjustBufferAfterFetch(rid) {
831811
// We need the item bindings to be processed before we can do adjustment
832812
return $timeout(() => {
833-
adapter.abfCount++;
834813
let keepFetching = processBufferedItems(rid);
835814

836815
if (viewport.shouldLoadBottom() && keepFetching) {
@@ -911,7 +890,6 @@ angular.module('ui.scroll', [])
911890

912891
function resizeAndScrollHandler() {
913892
if (!$rootScope.$$phase && !adapter.isLoading) {
914-
adapter.sCount++;
915893
if (viewport.shouldLoadBottom()) {
916894
enqueueFetch(ridActual, true);
917895
} else if (viewport.shouldLoadTop()) {

test/AdapterTestsSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ describe('uiScroll', function () {
10991099
scope.adapter.reload();
11001100
$timeout.flush();
11011101

1102-
expect(scope.adapter.topVisible).toBe('item1');
1102+
expect(scope.adapter.topVisible).toBe('item100');
11031103
}
11041104
);
11051105
});

0 commit comments

Comments
 (0)