Class: Collection

Collection

new Collection()

Collection

Collection of resources returned by Resource#query.

Source:

Methods

hasNext() → {Boolean}

Check if there is next page available.

This method doesn't trigger any external request. The resolution is based on the result of the last query.

Source:
Returns:

has next page

Type
Boolean
Example
var collection = Resource.query();
if (collection.hasNext()) {
  collection.nextPage();
}

hasPrev() → {Boolean}

Check if there is previous page available.

This method doesn't trigger any external request. The resolution is based on the result of the last query.

Source:
Returns:

has previous page

Type
Boolean
Example
var collection = Resource.query();
if (collection.hasPrev()) {
  collection.prevPage();
}

nextPage() → {Promise}

Fetch next page of collection and append resources to current instance of collection.

Source:
Throws:

When next page not available. You should check #hasNext before calling nextPage().

Type
RangeError
Returns:

promise

Type
Promise
Examples
var collection = Resource.query();
collection.then(function() {
  if (collection.hasNext()) {
    var promise = collection.nextPage();
    promise.then(function(data) {
      // next page has been fetched
      // `data` contains the newly fetched resources
      // `collection` now contains all resources
    });
  }
});
// Don't attach `then` to the `collection` because that was already resolved earlier as a response to #query.
var promise = collection.nextPage();
collection.then(function() {
  // WRONG. Already resolved.
});
promise.then(function() {
  // CORRECT. Will be resolved when next page is fetched.
});

prevPage() → {Promise}

Fetch previous page of collection and prepend items to current instance of collection.

Source:
Throws:

When previous page not available. You should check #hasPrev before calling prevPage().

Type
RangeError
Returns:

promise

Type
Promise
Examples
var collection = Resource.query();
collection.then(function() {
  if (collection.hasPrev()) {
    var promise = collection.prevPage();
    promise.then(function(data) {
      // previous page has been fetched
      // `data` contains the newly fetched resources
      // `collection` now contains all resources
    });
  }
});
// Don't attach `then` to the `collection` because that was already resolved earlier as a response to #query.
var promise = collection.prevPage();
collection.then(function() {
  // WRONG. Already resolved.
});
promise.then(function() {
  // CORRECT. Will be resolved when previous page is fetched.
});