Skip to content

Instantly share code, notes, and snippets.

@alex35mil
Last active March 17, 2017 17:40
Show Gist options
  • Save alex35mil/b5d074eac0fe2c1df4fbbf254ecd59ab to your computer and use it in GitHub Desktop.
Save alex35mil/b5d074eac0fe2c1df4fbbf254ecd59ab to your computer and use it in GitHub Desktop.
// Action creator: returns success action
const successAction = postId => ({
type: 'POST_DELETE_SUCCEEDED',
postId,
});
// Action handlers: passing array of the reducers for this action type
// to apply sequence of the changes to the state tree
const onSuccess = {
POST_DELETE_SUCCEEDED: [
// 1. hide spinner
(state, { postId }) =>
state.update('processingPosts', processingPosts => processingPosts.delete(postId)),
// 2. remove post entity
{
leaf: ['entities', 'posts'], // <= keypath to the leaf of the state
reduce:
(postsEntitiesState, { postId }) =>
postsEntitiesState
.updateIn(['index'], index => index.delete(postId))
.updateIn(['entities'], entities => entities.delete(postId)),
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment