Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(connectInfiniteHits): always set a value for previous page (#1195)
Browse files Browse the repository at this point in the history
* fix(connectInfiniteHits): prevent previous page to be not defined

* refactor(connectInfiniteHits): rename previousPage for _previousPage
  • Loading branch information
samouss authored May 14, 2018
1 parent 810eb7e commit 4c218d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default createConnector({
const results = getResults(searchResults, this.context);

this._allResults = this._allResults || [];
this._previousPage = this._previousPage || 0;

if (!results) {
return {
Expand All @@ -56,16 +57,16 @@ export default createConnector({

if (page === 0) {
this._allResults = hits;
} else if (page > this.previousPage) {
} else if (page > this._previousPage) {
this._allResults = [...this._allResults, ...hits];
} else if (page < this.previousPage) {
} else if (page < this._previousPage) {
this._allResults = hits;
}

const lastPageIndex = nbPages - 1;
const hasMore = page < lastPageIndex;

this.previousPage = page;
this._previousPage = page;

return {
hits: this._allResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('connectInfiniteHits', () => {
};

const expectation = {
hits: [],
hits: [{}, {}, {}],
hasMore: true,
};

Expand Down

0 comments on commit 4c218d5

Please sign in to comment.