Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial implementation #3

Merged
merged 31 commits into from
Apr 25, 2016
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9681a81
Add initial implementation
Mar 22, 2016
9d27a83
Refactor module imports
Mar 22, 2016
476f810
Refactor the paginator to cache promises instead of responses
Mar 22, 2016
c857f21
Update dependency list
Mar 22, 2016
e844e6c
Merge master
Apr 11, 2016
cc38b8f
Refactor paginator into seperate modules
Apr 11, 2016
1814d4e
Minor fixes
Apr 11, 2016
e5be062
Update npm scripts
Apr 12, 2016
824c2f5
Update documentation
Apr 12, 2016
99da1be
Remove unused files
Apr 14, 2016
dfbf7cb
Update package.json
Apr 14, 2016
a75dc94
Remove unused whatwg-fetch devDependency
Apr 14, 2016
54ea997
Correct invalid page handling
Apr 14, 2016
d5ee103
Add coverage reporting
Apr 14, 2016
0e0fadd
Tweak docs
Apr 14, 2016
e664deb
Correct test descriptions and typos
Apr 14, 2016
5b32e88
Update comments in API doc to be REPL like
Apr 14, 2016
ea48a9b
Remove Karma
Apr 21, 2016
39dad7e
Remove unused test code
Apr 21, 2016
33c9f5e
Rename variables for clarity
Apr 21, 2016
91bce54
Add default values to the query handlers
Apr 21, 2016
b57de47
Simplify resolvePage to a single purpose
Apr 21, 2016
7b628b2
Add tests for 100% coverage
Apr 21, 2016
9de4f7b
Add line breaks
Apr 21, 2016
632f79d
Correct grammar
Apr 21, 2016
8dc65c7
Update invalid page handling to reject an error
Apr 21, 2016
088ced4
Add missing semicolon
Apr 21, 2016
5b1b7f3
Simplify actions
Apr 22, 2016
ddc43d8
Change absolute modules paths to be relative
Apr 25, 2016
3a22f42
Remove unneeded app-module-path dependency
Apr 25, 2016
670abb9
Remove the browserify paths option
Apr 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor the paginator to cache promises instead of responses
Morris Allison III committed Mar 22, 2016
commit 476f810457faaf628bb7d0f64adf4af7f83b1c88
41 changes: 21 additions & 20 deletions src/paginator.js
Original file line number Diff line number Diff line change
@@ -86,31 +86,32 @@ export class Paginator {
}

fetchPage(page) {
if (this._hasResponse(page)) {
const response = this._getResponse(page);
let request;

return Promise.resolve(response.clone());
}

const request = this._sendRequest(page);
const cacheResponse = (response) => {
this._cacheResponse(page, response);
};
const makeResponseClone = function() {
return request.then((res) => res.clone());
};
const parseResponse = this._parseResponse.bind(this);

if (this._hasRequest(page)) {
request = this._getRequest(page);

return makeResponseClone();
}

request = this._sendRequest(page);

this._cacheRequest(page, request);

const parseResponseBody = this._parseResponseBody.bind(this);
const setLimitIfMissing = (parsed) => {
if (!this._limit) {
this._limit = parsed.limit;
}
};

return request
.then(cacheResponse)
.then(makeResponseClone)
return makeResponseClone()
.then(getResponseBody)
.then(parseResponse)
.then(parseResponseBody)
.then(setLimitIfMissing)
.then(makeResponseClone);
}
@@ -155,15 +156,15 @@ export class Paginator {
return queryParams;
}

_getResponse(page) {
_getRequest(page) {
return this._cache[page];
}

_cacheResponse(page, response) {
_cacheRequest(page, response) {
this._cache[page] = response;
}

_hasResponse(page) {
_hasRequest(page) {
return !!this._cache[page];
}

@@ -172,16 +173,16 @@ export class Paginator {
return this._parsedResponse;
}

const parseResponse = this._parseResponse.bind(this);
const parseResponseBody = this._parseResponseBody.bind(this);

this._parsedResponse = this.fetchPage(page)
.then(getResponseBody)
.then(parseResponse);
.then(parseResponseBody);

return this._parsedResponse;
}

_parseResponse(responseBody) {
_parseResponseBody(responseBody) {
const {count, results} = responseBody;
const limit = this._inferLimit(responseBody);
let pageCount = 1;