Implement shallow compare for the journal reducer.
The reason why we need it is that we don't have a concept of etag for journal fetching, which means we were setting the store on each fetch causing everything that depends on the journals to invalidate. This triggers a bug that causes the entries not to refresh if the journals haven't changed.master
parent
2aa92f15e7
commit
e58ddf8545
|
@ -39,6 +39,7 @@ export type JournalsData = List<EteSync.Journal>;
|
|||
|
||||
const JournalsFetchRecord = fetchTypeRecord<JournalsData>();
|
||||
export type JournalsType = FetchType<JournalsData>;
|
||||
export type JournalsTypeImmutable = Record<JournalsType>;
|
||||
|
||||
export type EntriesData = List<EteSync.Entry>;
|
||||
|
||||
|
@ -118,7 +119,30 @@ export const entries = handleAction(
|
|||
|
||||
const journals = handleAction(
|
||||
actions.fetchJournals,
|
||||
fetchTypeIdentityReducer,
|
||||
(state: JournalsTypeImmutable, action: any) => {
|
||||
const newState = fetchTypeIdentityReducer(state, action);
|
||||
// Compare the states and see if they are really different
|
||||
const oldJournals = state.get('value', null);
|
||||
const newJournals = newState.get('value', null);
|
||||
|
||||
if (!oldJournals || !newJournals || (oldJournals.size !== newJournals.size)) {
|
||||
return newState;
|
||||
}
|
||||
|
||||
let oldJournalHash = {};
|
||||
oldJournals.forEach((x) => {
|
||||
oldJournalHash[x.uid] = x.serialize();
|
||||
});
|
||||
|
||||
if (newJournals.every((journal: EteSync.Journal) => (
|
||||
(journal.uid in oldJournalHash) &&
|
||||
(journal.serialize().content === oldJournalHash[journal.uid].content)
|
||||
))) {
|
||||
return state;
|
||||
} else {
|
||||
return newState;
|
||||
}
|
||||
},
|
||||
new JournalsFetchRecord(),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue