diff --git a/demo/append/append.js b/demo/append/append.js index b17cfeab..6ed53658 100644 --- a/demo/append/append.js +++ b/demo/append/append.js @@ -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); @@ -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]); } }; diff --git a/src/ui-scroll.js b/src/ui-scroll.js index 05c90cd4..3b48cf9f 100644 --- a/src/ui-scroll.js +++ b/src/ui-scroll.js @@ -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)) {