Skip to content

Commit 72282c7

Browse files
committed
bof/eof info is accessible out of the scroller
1 parent dad5940 commit 72282c7

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

demo/append/append.js

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,13 @@ app.factory('Server', [
5151

5252
$timeout(function () {
5353
var item, result = {
54-
items: [],
55-
bof: false,
56-
eof: false
54+
items: []
5755
};
5856
if (start <= end) {
5957
for (var i = start; i <= end; i++) {
6058
if (item = self.getItem(i)) {
6159
result.items.push(item);
6260
}
63-
else { // if no item then begin or end of file is reached
64-
if (start <= self.first - self.prependedData.length) {
65-
result.bof = true;
66-
}
67-
if (end > self.max + self.appendedData.length) {
68-
result.eof = true;
69-
}
70-
}
7161
}
7262
}
7363
deferred.resolve(result);
@@ -104,43 +94,28 @@ app.factory('Server', [
10494
app.controller('mainController', [
10595
'$scope', 'Server', function ($scope, Server) {
10696

107-
var bof = false, eof = false;
108-
109-
function mySuccess(result, success) {
110-
bof = eof = false;
111-
if (result.bof) {
112-
bof = true;
113-
console.log('begin of file is reached');
114-
}
115-
if (result.eof) {
116-
eof = true;
117-
console.log('end of file is reached');
118-
}
119-
if (result.items.length) {
120-
console.log('resolved ' + result.items.length + ' items');
121-
}
122-
success(result.items);
123-
}
124-
12597
$scope.datasource = {
12698
get: function (index, count, success) {
12799
console.log('request by index = ' + index + ', count = ' + count);
128100
Server.request(index, count).then(function (result) {
129-
mySuccess(result, success);
101+
if (result.items.length) {
102+
console.log('resolved ' + result.items.length + ' items');
103+
}
104+
success(result.items);
130105
});
131106
}
132107
};
133108

134109
$scope.prepend = function () {
135110
var newItem = Server.prependItem(' (new)*');
136-
if (bof) {
111+
if ($scope.adapter.isBOF()) {
137112
$scope.adapter.prepend([newItem]);
138113
}
139114
};
140115

141116
$scope.append = function () {
142117
var newItem = Server.appendItem(' (new)*');
143-
if (eof) {
118+
if ($scope.adapter.isEOF()) {
144119
$scope.adapter.append([newItem]);
145120
}
146121
};

src/ui-scroll.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ angular.module('ui.scroll', [])
436436
});
437437

438438
this.isLoading = false;
439+
this.isBOF = () => buffer.bof;
440+
this.isEOF = () => buffer.eof;
439441

440442
this.applyUpdates = (arg1, arg2) => {
441443
if (angular.isFunction(arg1)) {

0 commit comments

Comments
 (0)