diff --git a/src/store/reducers.ts b/src/store/reducers.ts index d277ea7..b6574de 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -39,6 +39,7 @@ export type JournalsData = List; const JournalsFetchRecord = fetchTypeRecord(); export type JournalsType = FetchType; +export type JournalsTypeImmutable = Record; export type EntriesData = List; @@ -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(), );