Skip to content

Commit 1e9fe4a

Browse files
committed
buffer cleanup should be consistent on forward direction with immutabeTop
1 parent dd81ad0 commit 1e9fe4a

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/modules/buffer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export default function ScrollBuffer(elementRoutines, bufferSize, startIndex) {
9696
buffer.next--;
9797
}
9898
if (!buffer.length) {
99-
buffer.first = 1;
100-
buffer.next = 1;
99+
buffer.minIndex = Math.min(buffer.maxIndex, buffer.minIndex);
101100
}
102101

103102
return elementRoutines.removeElementAnimated(arg1);

test/AdapterTestsSpec.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ describe('uiScroll', function () {
15971597

15981598
it('scroll to the bottom', function () {
15991599
runTest(scrollSettings,
1600-
function (viewport, scope) {
1600+
function (viewport, scope) {
16011601
viewport.scrollTop(10000);
16021602
viewport.trigger('scroll');
16031603

@@ -1610,4 +1610,52 @@ describe('uiScroll', function () {
16101610

16111611
});
16121612

1613+
describe('buffer cleanup', function () {
1614+
var scrollSettings = { datasource: 'myEdgeDatasource', adapter: 'adapter', viewportHeight: 60, itemHeight: 20, padding: 0.3, startIndex: 3, bufferSize: 3 };
1615+
1616+
injectDatasource('myEdgeDatasource');
1617+
1618+
var cleanBuffer = function (scope) {
1619+
var get = datasource.get;
1620+
var removedItems = [];
1621+
// sync the datasource
1622+
datasource.get = function (index, count, success) {
1623+
get(index, count, function (result) {
1624+
result = result.filter(function (item) {
1625+
return removedItems.indexOf(item) === -1;
1626+
});
1627+
success(result);
1628+
});
1629+
};
1630+
// clean up the buffer
1631+
scope.adapter.applyUpdates(
1632+
function (item) {
1633+
removedItems.push(item);
1634+
return [];
1635+
}, {
1636+
immutableTop: true
1637+
}
1638+
);
1639+
};
1640+
1641+
it('should be consistent on forward direction with immutabeTop', function () {
1642+
runTest(scrollSettings,
1643+
function (viewport, scope) {
1644+
expect(scope.adapter.isBOF()).toBe(false);
1645+
expect(scope.adapter.isEOF()).toBe(true);
1646+
1647+
// remove items 0..6 items form -5..6 datasource
1648+
cleanBuffer(scope);
1649+
1650+
expect(scope.adapter.isBOF()).toBe(true);
1651+
expect(scope.adapter.isEOF()).toBe(true);
1652+
expect(scope.adapter.bufferFirst).toBe('item-5');
1653+
expect(scope.adapter.bufferLast).toBe('item-1');
1654+
expect(scope.adapter.bufferLength).toBe(5);
1655+
}
1656+
);
1657+
});
1658+
1659+
});
1660+
16131661
});

0 commit comments

Comments
 (0)