Consider about ImmerReducer
Brooooooklyn opened this issue · 0 comments
Brooooooklyn commented
Using immer in complicated state is much more concise than POJ.
For example:
interface State: {
ui: {
comments: { [index: string]: Array<Comment> }
}
}@ImmerReducer()
addComment(state: State, { payload }: Action<{ articleId: string, comment: Comment }>) {
state.ui.comments[payload.articleId].push(payload.comment)
}vs
@Reducer()
addComment(state: State, { payload }: Action<{ articleId: string, comment: Comment }>) {
const comments = state.ui.comments.get(payload.article)
return { ...state, ui: { ...state.ui, comments: { ...state.ui.comments, [payload.articleId]: [...comments, payload.comment] } } }
}