Skip to content

Commit

Permalink
Merge pull request #29 from social-native/feat/add-rehydration-flag
Browse files Browse the repository at this point in the history
Feat: add rehydration flag
  • Loading branch information
erhathaway authored Mar 12, 2020
2 parents e7c093b + 54ce998 commit 1d13fc6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ IHistoryPersister {
| ---------------- | ------------------------------------------------------------ | --------------------------------------------------------------------- |
| history | the recorded history | `Array<HistoryLocation | undefined>` |
| currentLocationInHistoryCursor | the location in history, changed by going 'back' or 'forward' | `number` |
| hasRehydratedLocation | flag to tell if any location was rehydrated from when the `rehydrate` method was called |

## Verbose Examples

Expand Down
37 changes: 27 additions & 10 deletions dev/app/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
localStorageHistoryPersister
} from '../../src';
import {IRangeConfig} from '../../src/filters/range_filter';
import {reaction} from 'mobx';
// import {toJS} from 'mobx';

const exampleFormInstance = new ExampleForm();
Expand Down Expand Up @@ -104,9 +105,9 @@ const creatorCRM = new Manager(client, {
});

// gqlClient.createClient().then(() => {
creatorCRM.getFieldNamesAndTypes().then(() => {
creatorCRM.runStartQuery();
});
// creatorCRM.getFieldNamesAndTypes().then(() => {
// creatorCRM.runStartQuery();
// });
// setTimeout(() => console.log('hur', toJS(creatorCRM.fieldsWithFiltersAndSuggestions)), 3000);
// });

Expand All @@ -128,14 +129,20 @@ const creatorCRMHistory = new History(creatorCRM, 'influencer_crm', {

(global as any).crmHistory = creatorCRMHistory;
(global as any).crm = creatorCRM;
setTimeout(() => {
// creatorCRMHistory.setCurrentState(
// JSON.parse(
// '{"filters":{"multiselect":{"fieldKinds":{"tags":"should"},"fieldFilters":{"tags":{"carolsdaugther":{"inclusion":"include"}}}},"exists":{"fieldKinds":{"instagram.id":"must"},"fieldFilters":{"instagram.id":{"exists":true}}},"range":{"fieldKinds":{"user_profile.age":"must"},"fieldFilters":{"user_profile.age":{"lessThan":68,"greaterThan":35}}}},"suggestions":{"prefix":{"fieldKinds":{"tags":"should"},"fieldSearches":{"tags":"car"}}}}'
// )
// );
// setTimeout(() => {
// creatorCRMHistory.setCurrentState(
// JSON.parse(
// '{"filters":{"multiselect":{"fieldKinds":{"tags":"should"},"fieldFilters":{"tags":{"carolsdaugther":{"inclusion":"include"}}}},"exists":{"fieldKinds":{"instagram.id":"must"},"fieldFilters":{"instagram.id":{"exists":true}}},"range":{"fieldKinds":{"user_profile.age":"must"},"fieldFilters":{"user_profile.age":{"lessThan":68,"greaterThan":35}}}},"suggestions":{"prefix":{"fieldKinds":{"tags":"should"},"fieldSearches":{"tags":"car"}}}}'
// )
// );

creatorCRM.getFieldNamesAndTypes().then(() => {
creatorCRMHistory.rehydrate();
}, 5000);
if (!creatorCRMHistory.hasRehydratedLocation) {
creatorCRM.runStartQuery();
}
});
// }, 5000);
// console.log(history);

export default {
Expand All @@ -144,3 +151,13 @@ export default {
creatorCRM: React.createContext(creatorCRM),
creatorCRMHistory: React.createContext(creatorCRMHistory)
};

reaction(
() => ({
queue: [...creatorCRM._sideEffectQueue],
isSideEffectRunning: !!creatorCRM.isSideEffectRunning
}),
data => {
console.log(creatorCRM._sideEffectQueue.map(k => k.kind));
}
);
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.5.0",
"version": "3.6.0",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
4 changes: 4 additions & 0 deletions src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class History {
public currentLocationInHistoryCursor: number;
public currentLocationStore: ICurrentLocationStore<HistoryLocation>;
public historyPersister: IHistoryPersister | undefined;
public hasRehydratedLocation: boolean;

constructor(
manager: Manager,
Expand All @@ -94,6 +95,7 @@ class History {
this.currentLocationInHistoryCursor = 0;
this.history = [];
this.historyPersister = options && options.historyPersister;
this.hasRehydratedLocation = false;
if (options && options.rehydrateOnStart) {
this.rehydrate();
}
Expand Down Expand Up @@ -146,6 +148,7 @@ class History {
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(
Expand All @@ -160,6 +163,7 @@ class History {
} else {
const existingStateFromUrl = this.currentLocationStore.getState();
if (existingStateFromUrl) {
this.hasRehydratedLocation = true;
this._rehydrateFromLocation(existingStateFromUrl);
}
}
Expand Down

0 comments on commit 1d13fc6

Please sign in to comment.