Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1b01db

Browse files
authored
Update Paginator.js
1 parent 84958aa commit e1b01db

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

modules/Paginator.js

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@
44
* @param paginate {function} Query function that takes paginationOptions
55
*
66
* @example
7-
* resolve: {
8-
* // Prepares the paginator
9-
* paginator: function(Paginator, Project) {
10-
* // Calls `Project.list(paginationOptions)`
11-
* return new Paginator(Project.list, { limit: 50 });
12-
* }
13-
* },
14-
* controller: function($scope, paginator) {
15-
* $scope.paginator = paginator; // ng-repeat="item in paginator.items"
16-
* paginator.next(); // asynchronously load the first dataset
17-
* }
7+
* let paginatedProjects = new Paginator(Project.list, { limit: 50 });
8+
* paginatedProjects.items; // data accessible here
9+
* paginatedProjects.next(); // load the first/subsequent data
1810
*
1911
* @example
20-
* resolve: {
21-
* taskPaginator: function(Paginator, Task, $stateParams) {
22-
* return new Paginator( (paginationOptions) => Task.list($stateParams.projectId, paginationOptions) );
23-
* // or
24-
* return new Paginator( Task.list, { projectId: $stateParams.projectId } );
25-
* },
26-
* controller: function($scope, taskPaginator) {
27-
* $scope.paginator = taskPaginator; // ng-repeat="item in paginator.items"
28-
* taskPaginator.next(); // asynchronously load the first dataset
29-
* }
12+
* let projectId = 23;
13+
* // Customize the paginator function
14+
* let paginatedTasks = new Paginator( (paginationOptions) => Task.list( projectId, paginationOptions) );
15+
*
16+
* @example
17+
* let projectId = 23;
18+
* // Set default parameters for paginator function
19+
* let paginatedTasks = new Paginator( Task.list, { projectId: projectId });
3020
*/
3121
angular.module('App').factory('Paginator', function($http, $q){
3222

@@ -48,7 +38,7 @@ angular.module('App').factory('Paginator', function($http, $q){
4838
}
4939

5040
/**
51-
* paginator.paginate - paginator function
41+
* The function that performs the query
5242
*
5343
* @param {url|function} paginate
5444
* If a url is provided, a wrapper for $http.get() is created
@@ -62,13 +52,14 @@ angular.module('App').factory('Paginator', function($http, $q){
6252
this._paginate = paginate;
6353
}
6454

55+
/**
56+
* @returns {function}
57+
*/
6558
get paginate() {
6659
return this._paginate;
6760
}
6861

6962
/**
70-
* reset()
71-
*
7263
* Clear items collection. Useful for preserving related data.
7364
*
7465
* @note If you want a hard reset of all related data, create a new Paginator
@@ -87,6 +78,10 @@ angular.module('App').factory('Paginator', function($http, $q){
8778
return this.items = [];
8879
}
8980

81+
/**
82+
* Load more items and add to cache
83+
* @param {Promise}
84+
*/
9085
next() {
9186
if (!this.hasMore) return $q.when();
9287
if (this.loading) return this.loading;
@@ -104,9 +99,7 @@ angular.module('App').factory('Paginator', function($http, $q){
10499
}
105100

106101
/**
107-
* add()
108-
*
109-
* Add item to this.items and populate related
102+
* Add item to cache and retrieve related data
110103
*
111104
* @param {index|object} item Reference to an object or the index
112105
*/
@@ -116,9 +109,7 @@ angular.module('App').factory('Paginator', function($http, $q){
116109
}
117110

118111
/**
119-
* remove()
120-
*
121-
* Remove item from this.items
112+
* Remove item from cache
122113
*
123114
* @param {index|object} item Reference to an object or the index
124115
*/
@@ -131,8 +122,6 @@ angular.module('App').factory('Paginator', function($http, $q){
131122
}
132123

133124
/**
134-
* getRelated(newItems)
135-
*
136125
* Iterates over related data retrieval helpers
137126
* When each helper resolves with a hash of relatedItems, they are merged onto
138127
* the paginator's existing cache of related items.

0 commit comments

Comments
 (0)