@@ -51,23 +51,13 @@ app.factory('Server', [
51
51
52
52
$timeout ( function ( ) {
53
53
var item , result = {
54
- items : [ ] ,
55
- bof : false ,
56
- eof : false
54
+ items : [ ]
57
55
} ;
58
56
if ( start <= end ) {
59
57
for ( var i = start ; i <= end ; i ++ ) {
60
58
if ( item = self . getItem ( i ) ) {
61
59
result . items . push ( item ) ;
62
60
}
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
- }
71
61
}
72
62
}
73
63
deferred . resolve ( result ) ;
@@ -104,43 +94,28 @@ app.factory('Server', [
104
94
app . controller ( 'mainController' , [
105
95
'$scope' , 'Server' , function ( $scope , Server ) {
106
96
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
-
125
97
$scope . datasource = {
126
98
get : function ( index , count , success ) {
127
99
console . log ( 'request by index = ' + index + ', count = ' + count ) ;
128
100
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 ) ;
130
105
} ) ;
131
106
}
132
107
} ;
133
108
134
109
$scope . prepend = function ( ) {
135
110
var newItem = Server . prependItem ( ' (new)*' ) ;
136
- if ( bof ) {
111
+ if ( $scope . adapter . isBOF ( ) ) {
137
112
$scope . adapter . prepend ( [ newItem ] ) ;
138
113
}
139
114
} ;
140
115
141
116
$scope . append = function ( ) {
142
117
var newItem = Server . appendItem ( ' (new)*' ) ;
143
- if ( eof ) {
118
+ if ( $scope . adapter . isEOF ( ) ) {
144
119
$scope . adapter . append ( [ newItem ] ) ;
145
120
}
146
121
} ;
0 commit comments