Last active
March 17, 2017 17:40
-
-
Save alex35mil/b5d074eac0fe2c1df4fbbf254ecd59ab 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: 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