Skip to content

Commit

Permalink
Merge pull request #30 from social-native/fix/rehydrate-flag
Browse files Browse the repository at this point in the history
Fix: rehydrate flag
  • Loading branch information
erhathaway authored Mar 12, 2020
2 parents 3ca5c66 + 3322956 commit 121cbf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@social-native/snpkg-client-elasticsearch",
"version": "3.6.0",
"version": "3.6.1",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
14 changes: 12 additions & 2 deletions src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,37 @@ class History {
* Rehydrates state from current state store (URL) or persistent storage (localStorage)
*/
public rehydrate = () => {
// tslint:disable-next-line
runInAction(() => {
if (this.historyPersister) {
const persistedHistory = this.historyPersister.getHistory();
this.history = persistedHistory;
if (persistedHistory.length > 0) {
this.hasRehydratedLocation = true;
const existingStateFromUrl = this.currentLocationStore.getState();
if (!existingStateFromUrl) {
const newHistoryLocation = this._deepCopy(
persistedHistory[0] as HistoryLocation
);
// if only suggestions are present then we should
// act as if no location was rehydrated
if (newHistoryLocation.filters) {
this.hasRehydratedLocation = true;
}
this.currentLocationStore.setState(newHistoryLocation);

this._rehydrateFromLocation(newHistoryLocation);
} else {
if (existingStateFromUrl.filters) {
this.hasRehydratedLocation = true;
}
this._rehydrateFromLocation(existingStateFromUrl);
}
} else {
const existingStateFromUrl = this.currentLocationStore.getState();
if (existingStateFromUrl) {
this.hasRehydratedLocation = true;
if (existingStateFromUrl.filters) {
this.hasRehydratedLocation = true;
}
this._rehydrateFromLocation(existingStateFromUrl);
}
}
Expand Down

0 comments on commit 121cbf5

Please sign in to comment.