Skip to content

Instantly share code, notes, and snippets.

@spion

spion/pager-promises.js

Last active Aug 29, 2015
Embed
What would you like to do?
function Pager(url) {
this._url = url;
this._prev = null; // Pager
this._data = null; // Promise<Data>, where Data { endKey, rows }
this._startKey = Promise.resolve(null);
}
Pager.prototype.data = function() {
if (!this._data)
this._data = this._startKey.then(key => getUrl(createUrlFrom(this._url, key)));
return this._data;
}
Pager.prototype.rows = function() {
return this.data().then(d => d.rows);
}
Pager.prototype.next = function() {
var pNext = new Pager(this._url);
pNext._prev = this;
pNext._startKey = this.data().then(data => data.endKey);
return pNext;
}
Pager.prototype.prev = function() {
return this._prev;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment