Skip to content

Commit

Permalink
bof/eof info is accessible out of the scroller
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed Jun 27, 2016
1 parent dad5940 commit 72282c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
39 changes: 7 additions & 32 deletions demo/append/append.js
Expand Up @@ -51,23 +51,13 @@ app.factory('Server', [

$timeout(function () {
var item, result = {
items: [],
bof: false,
eof: false
items: []
};
if (start <= end) {
for (var i = start; i <= end; i++) {
if (item = self.getItem(i)) {
result.items.push(item);
}
else { // if no item then begin or end of file is reached
if (start <= self.first - self.prependedData.length) {
result.bof = true;
}
if (end > self.max + self.appendedData.length) {
result.eof = true;
}
}
}
}
deferred.resolve(result);
Expand Down Expand Up @@ -104,43 +94,28 @@ app.factory('Server', [
app.controller('mainController', [
'$scope', 'Server', function ($scope, Server) {

var bof = false, eof = false;

function mySuccess(result, success) {
bof = eof = false;
if (result.bof) {
bof = true;
console.log('begin of file is reached');
}
if (result.eof) {
eof = true;
console.log('end of file is reached');
}
if (result.items.length) {
console.log('resolved ' + result.items.length + ' items');
}
success(result.items);
}

$scope.datasource = {
get: function (index, count, success) {
console.log('request by index = ' + index + ', count = ' + count);
Server.request(index, count).then(function (result) {
mySuccess(result, success);
if (result.items.length) {
console.log('resolved ' + result.items.length + ' items');
}
success(result.items);
});
}
};

$scope.prepend = function () {
var newItem = Server.prependItem(' (new)*');
if (bof) {
if ($scope.adapter.isBOF()) {
$scope.adapter.prepend([newItem]);
}
};

$scope.append = function () {
var newItem = Server.appendItem(' (new)*');
if (eof) {
if ($scope.adapter.isEOF()) {
$scope.adapter.append([newItem]);
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/ui-scroll.js
Expand Up @@ -436,6 +436,8 @@ angular.module('ui.scroll', [])
});

this.isLoading = false;
this.isBOF = () => buffer.bof;
this.isEOF = () => buffer.eof;

this.applyUpdates = (arg1, arg2) => {
if (angular.isFunction(arg1)) {
Expand Down

0 comments on commit 72282c7

Please sign in to comment.