Skip to content

Instantly share code, notes, and snippets.

@alex35mil
Last active February 28, 2017 07:56
Show Gist options
  • Save alex35mil/006c97d67a98ef0f5de3d3b5ba2fa02a to your computer and use it in GitHub Desktop.
Save alex35mil/006c97d67a98ef0f5de3d3b5ba2fa02a to your computer and use it in GitHub Desktop.
// 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