Skip to content

Commit e61f46a

Browse files
committed
out-of-buffer demo, interim build
1 parent 68335e2 commit e61f46a

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

demo/outOfBuffer/outOfBuffer.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,30 @@ app.factory('Server', [
8383
return this.returnDeferredResult(newItem);
8484
},
8585

86+
removeFirst: function () {
87+
var firstItem = this.data.find(i => i.index === this.firstIndex);
88+
if(!firstItem) {
89+
return;
90+
}
91+
return this.removeItemById(firstItem.id);
92+
},
93+
94+
removeLast: function () {
95+
var lastItem = this.data.find(i => i.index === this.lastIndex);
96+
if(!lastItem) {
97+
return;
98+
}
99+
return this.removeItemById(lastItem.id);
100+
},
101+
86102
removeItemById: function (itemId) {
87103
var length = this.data.length;
88104
for (var i = 0; i < length; i++) {
89105
if (this.data[i].id === itemId) {
106+
var indexRemoved = this.data[i].index;
90107
this.data.splice(i, 1);
91108
this.setIndicies();
92-
return this.returnDeferredResult(true);
109+
return this.returnDeferredResult(indexRemoved);
93110
}
94111
}
95112
return this.returnDeferredResult(false);
@@ -171,7 +188,7 @@ app.controller('mainController', [
171188

172189
ctrl.remove = function (itemRemove) {
173190
Server.removeItemById(itemRemove.id).then(function (result) {
174-
if (result) {
191+
if (result !== false) {
175192
ctrl.adapter.applyUpdates(function (item) {
176193
if (item.id === itemRemove.id) {
177194
return [];
@@ -181,31 +198,20 @@ app.controller('mainController', [
181198
});
182199
};
183200

184-
ctrl.removeLast = function () {
185-
const lastIndex = Server.lastIndex;
186-
const lastItem = Server.data.find(i => i.index === Server.lastIndex);
187-
if(!lastItem) {
188-
return;
189-
}
190-
Server.removeItemById(lastItem.id).then(function (result) {
191-
if (result) {
192-
ctrl.adapter.applyUpdates(lastIndex, []);
201+
ctrl.removeFirst = function () {
202+
Server.removeFirst().then(function (indexRemoved) {
203+
if (indexRemoved !== false) {
204+
ctrl.adapter.applyUpdates(indexRemoved, []);
193205
}
194206
});
195207
};
196208

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, []);
209+
ctrl.removeLast = function () {
210+
Server.removeLast().then(function (indexRemoved) {
211+
if (indexRemoved !== false) {
212+
ctrl.adapter.applyUpdates(indexRemoved, []);
206213
}
207214
});
208215
};
209-
210216
}
211217
]);

dist/ui-scroll.js

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-scroll.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/PaddingCacheSpec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ describe('uiScroll Paddings cache', function () {
55
beforeEach(module('ui.scroll'));
66
beforeEach(module('ui.scroll.test.datasources'));
77

8-
describe('applyUpdates tests\n', function () {
8+
describe('applyUpdates out of buffer\n', function () {
99
var itemsCount = 30;
1010
var itemHeight = 100;
1111
var viewportHeight = 500;
12-
var MAX = 999999;
1312

1413
var scrollSettings = {
1514
datasource: 'myResponsiveDatasource',
@@ -32,7 +31,7 @@ describe('uiScroll Paddings cache', function () {
3231

3332
function scrollBottom(viewport, count = 1) {
3433
for (var i = 0; i < count; i++) {
35-
viewport.scrollTop(MAX);
34+
viewport.scrollTop(99999);
3635
viewport.trigger('scroll');
3736
}
3837
}

0 commit comments

Comments
 (0)