Store: handle addJournal correctly (include empty entry list).

Fixes #35.
master
Tom Hacohen 6 years ago
parent aeca32afa8
commit ae3f32cc01

@ -193,13 +193,23 @@ const mapReducerActionsMapCreator = <T extends Record<any>, V extends BaseModel>
}; };
}; };
export const entries = handleAction( function fetchCreateEntriesReducer(state: EntriesTypeImmutable, action: any) {
combineActions(actions.fetchEntries, actions.createEntries), const prevState = state.get(action.meta.journal);
(state: EntriesTypeImmutable, action: any) => { const extend = action.meta.prevUid != null;
const prevState = state.get(action.meta.journal); return state.set(action.meta.journal,
const extend = action.meta.prevUid != null; fetchTypeIdentityReducer(prevState, action, extend));
return state.set(action.meta.journal, }
fetchTypeIdentityReducer(prevState, action, extend));
export const entries = handleActions(
{
[actions.fetchEntries.toString()]: fetchCreateEntriesReducer,
[actions.createEntries.toString()]: fetchCreateEntriesReducer,
[actions.addJournal.toString()]: (state: EntriesTypeImmutable, action: any) => {
const journal = action.meta.item.uid;
const prevState = state.get(journal);
return state.set(journal,
fetchTypeIdentityReducer(prevState, { payload: [] }, false));
},
}, },
ImmutableMap({}) ImmutableMap({})
); );

Loading…
Cancel
Save