Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Action creator: dispatched from the thunk or whatever
const successAction = (entityId, data) => ({
type: UPDATE_SUCCEEDED,
entityId,
data,
});
// Changes in the app state:
// Action handler -> ui/unitStore: resetting UI unit state
const onSuccess = {
[UPDATE_SUCCEEDED]: () => initialState,
};
// Action handler -> data/entitiesStore: updating entity in the data store
const updateEntityOnEdit = {
[UPDATE_SUCCEEDED]:
(state, { entityId, data }) =>
state.mergeIn(['entities', entityId], data),
};
// Failure handlers, thunks, etc...
// --- Exports
// Imported to the UI unit reducer
export const onServerStateUpdate = {
...onRequest, // showing spinner
...onSuccess, // resetting state
...onFailure, // handling errors
};
// Imported to the data store reducer
export { updateEntityOnEdit };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.