4
4
* @param paginate {function} Query function that takes paginationOptions
5
5
*
6
6
* @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
18
10
*
19
11
* @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 });
30
20
*/
31
21
angular . module ( 'App' ) . factory ( 'Paginator' , function ( $http , $q ) {
32
22
@@ -48,7 +38,7 @@ angular.module('App').factory('Paginator', function($http, $q){
48
38
}
49
39
50
40
/**
51
- * paginator.paginate - paginator function
41
+ * The function that performs the query
52
42
*
53
43
* @param {url|function } paginate
54
44
* If a url is provided, a wrapper for $http.get() is created
@@ -62,13 +52,14 @@ angular.module('App').factory('Paginator', function($http, $q){
62
52
this . _paginate = paginate ;
63
53
}
64
54
55
+ /**
56
+ * @returns {function }
57
+ */
65
58
get paginate ( ) {
66
59
return this . _paginate ;
67
60
}
68
61
69
62
/**
70
- * reset()
71
- *
72
63
* Clear items collection. Useful for preserving related data.
73
64
*
74
65
* @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){
87
78
return this . items = [ ] ;
88
79
}
89
80
81
+ /**
82
+ * Load more items and add to cache
83
+ * @param {Promise }
84
+ */
90
85
next ( ) {
91
86
if ( ! this . hasMore ) return $q . when ( ) ;
92
87
if ( this . loading ) return this . loading ;
@@ -104,9 +99,7 @@ angular.module('App').factory('Paginator', function($http, $q){
104
99
}
105
100
106
101
/**
107
- * add()
108
- *
109
- * Add item to this.items and populate related
102
+ * Add item to cache and retrieve related data
110
103
*
111
104
* @param {index|object } item Reference to an object or the index
112
105
*/
@@ -116,9 +109,7 @@ angular.module('App').factory('Paginator', function($http, $q){
116
109
}
117
110
118
111
/**
119
- * remove()
120
- *
121
- * Remove item from this.items
112
+ * Remove item from cache
122
113
*
123
114
* @param {index|object } item Reference to an object or the index
124
115
*/
@@ -131,8 +122,6 @@ angular.module('App').factory('Paginator', function($http, $q){
131
122
}
132
123
133
124
/**
134
- * getRelated(newItems)
135
- *
136
125
* Iterates over related data retrieval helpers
137
126
* When each helper resolves with a hash of relatedItems, they are merged onto
138
127
* the paginator's existing cache of related items.
0 commit comments