Skip to content

Commit c12a2e6

Browse files
committed
remove single item from top: test and demo
1 parent b137d6f commit c12a2e6

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

demo/outOfBuffer/outOfBuffer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<button ng-click="mainCtrl.prepend()">Prepend one item</button>
3030
<button ng-click="mainCtrl.append()">Append one item</button>
3131
<!--button ng-click="mainCtrl.removeAll()">Clear the viewport</button-->
32+
<button ng-click="mainCtrl.removeFirst()">Remove first</button>
3233
<button ng-click="mainCtrl.removeLast()">Remove last</button>
3334
</div>
3435

demo/outOfBuffer/outOfBuffer.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ app.controller('mainController', [
185185
const lastIndex = Server.lastIndex;
186186
const lastItem = Server.data.find(i => i.index === Server.lastIndex);
187187
if(!lastItem) {
188-
retirn;
188+
return;
189189
}
190190
Server.removeItemById(lastItem.id).then(function (result) {
191191
if (result) {
@@ -194,5 +194,18 @@ app.controller('mainController', [
194194
});
195195
};
196196

197+
ctrl.removeFirst = function () {
198+
const firstIndex = Server.firstIndex;
199+
const firstItem = Server.data.find(i => i.index === Server.firstIndex);
200+
if(!firstItem) {
201+
return;
202+
}
203+
Server.removeItemById(firstItem.id).then(function (result) {
204+
if (result) {
205+
ctrl.adapter.applyUpdates(firstIndex, []);
206+
}
207+
});
208+
};
209+
197210
}
198211
]);

test/PaddingCacheSpec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ describe('uiScroll Paddings cache', function () {
1919
return parseInt(angular.element(bottomPadding).css('height'), 10);
2020
}
2121

22+
function getTopPaddingHeight(viewport) {
23+
var viewportChildren = viewport.children();
24+
var topPadding = viewportChildren[0];
25+
return parseInt(angular.element(topPadding).css('height'), 10);
26+
}
27+
2228
var initialBottomHeight = 240;
2329

24-
it('should delete last row out of buffer', function () {
30+
it('should delete last row when out of buffer', function () {
2531
runTest(scrollSettings,
2632
function (viewport, scope) {
2733

@@ -40,6 +46,23 @@ describe('uiScroll Paddings cache', function () {
4046
);
4147
});
4248

49+
it('should delete first when row out of buffer', function () {
50+
runTest(scrollSettings,
51+
function (viewport, scope) {
52+
53+
viewport.scrollTop(1000);
54+
viewport.trigger('scroll');
55+
viewport.scrollTop(1000);
56+
viewport.trigger('scroll');
57+
58+
// expect(getTopPaddingHeight(viewport)).toBe(initialBottomHeight);
59+
// scope.adapter.applyUpdates(1, []);
60+
// expect(getTopPaddingHeight(viewport)).toBe(initialBottomHeight - scrollSettings.itemHeight);
61+
62+
}
63+
);
64+
});
65+
4366
});
4467

4568
});

0 commit comments

Comments
 (0)