Skip to content

Commit 9f431e0

Browse files
committed
buffer cleanp when bof without immutableTop
1 parent b8b512d commit 9f431e0

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/modules/adapter.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ class Adapter {
172172
if (!newItems.reverse().some(newItem => newItem === wrapper.item)) {
173173
wrapper.op = OPERATIONS.REMOVE;
174174
// try to catch "first" edge case on remove
175-
if (!options.immutableTop && position === 0 && !newItems.length) {
176-
wrapper.shiftTop = true;
175+
if (!options.immutableTop && !newItems.length) {
176+
// this is the first item, or the previous one's part of the "shift-top" group
177+
if (position === 0 || this.buffer[position - 1].shiftTop) {
178+
wrapper.shiftTop = true;
179+
}
177180
}
178181
}
179182
newItems.forEach((newItem) => {

test/AdapterTestsSpec.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,22 +1611,23 @@ describe('uiScroll', function () {
16111611
});
16121612

16131613
describe('buffer cleanup', function () {
1614-
var scrollSettings = {
1615-
datasource: 'myEdgeDatasource',
1616-
adapter: 'adapter',
1617-
viewportHeight: 60,
1618-
itemHeight: 20,
1619-
padding: 0.3,
1620-
startIndex: 3,
1621-
bufferSize: 3
1614+
var getSettings = function () {
1615+
return {
1616+
datasource: 'myEdgeDatasource',
1617+
adapter: 'adapter',
1618+
viewportHeight: 60,
1619+
itemHeight: 20,
1620+
padding: 0.3,
1621+
startIndex: 3,
1622+
bufferSize: 3
1623+
};
16221624
};
16231625

16241626
injectDatasource('myEdgeDatasource');
16251627

1626-
var cleanBuffer = function (datasource, scope, applyUpdateOptions) {
1628+
var cleanBuffer = function (scope, applyUpdateOptions) {
16271629
var get = datasource.get;
16281630
var removedItems = [];
1629-
var first = -5;
16301631
// sync the datasource
16311632
datasource.get = function (index, count, success) {
16321633
var removedIndex = removedItems.indexOf('item' + index);
@@ -1644,13 +1645,13 @@ describe('uiScroll', function () {
16441645
};
16451646

16461647
it('should be consistent on forward direction when eof with immutabeTop', function () {
1647-
runTest(scrollSettings,
1648+
runTest(getSettings(),
16481649
function (viewport, scope) {
16491650
expect(scope.adapter.isBOF()).toBe(false);
16501651
expect(scope.adapter.isEOF()).toBe(true);
16511652

16521653
// remove items 0..6 items form -5..6 datasource
1653-
cleanBuffer(datasource, scope, { immutableTop: true });
1654+
cleanBuffer(scope, { immutableTop: true });
16541655

16551656
// result [-5..-1]
16561657
expect(scope.adapter.isBOF()).toBe(true);
@@ -1660,9 +1661,10 @@ describe('uiScroll', function () {
16601661
expect(scope.adapter.bufferLength).toBe(5);
16611662
}
16621663
);
1663-
});
1664+
});
16641665

16651666
it('should be consistent on forward direction when not eof with immutabeTop', function () {
1667+
var scrollSettings = getSettings();
16661668
scrollSettings.startIndex = -1;
16671669
scrollSettings.viewportHeight = 40;
16681670
runTest(scrollSettings,
@@ -1671,7 +1673,7 @@ describe('uiScroll', function () {
16711673
expect(scope.adapter.isEOF()).toBe(false);
16721674

16731675
// remove items -4..1 items form -5..6 datasource
1674-
cleanBuffer(datasource, scope, { immutableTop: true });
1676+
cleanBuffer(scope, { immutableTop: true });
16751677

16761678
// result [-5, 2, 3, 4]
16771679
expect(scope.adapter.isBOF()).toBe(true);
@@ -1683,6 +1685,27 @@ describe('uiScroll', function () {
16831685
);
16841686
});
16851687

1688+
it('should be consistent on backward direction when bof without immutableTop', function () {
1689+
var scrollSettings = getSettings();
1690+
scrollSettings.startIndex = -3;
1691+
scrollSettings.padding = 0.5;
1692+
runTest(scrollSettings,
1693+
function (viewport, scope) {
1694+
expect(scope.adapter.isBOF()).toBe(true);
1695+
expect(scope.adapter.isEOF()).toBe(false);
1696+
1697+
// remove items -5..1 items form -5..6 datasource
1698+
cleanBuffer(scope);
1699+
1700+
expect(scope.adapter.isBOF()).toBe(true);
1701+
expect(scope.adapter.isEOF()).toBe(true);
1702+
expect(scope.adapter.bufferFirst).toBe('item2');
1703+
expect(scope.adapter.bufferLast).toBe('item6');
1704+
expect(scope.adapter.bufferLength).toBe(5);
1705+
}
1706+
);
1707+
});
1708+
16861709
});
16871710

16881711
});

0 commit comments

Comments
 (0)