Last active
February 28, 2017 07:56
-
-
Save alex35mil/006c97d67a98ef0f5de3d3b5ba2fa02a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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