Open the-dr-lazy opened 5 years ago
Also in many cases error
and cancel
have shared logic.
A solution for shared logic is to handle cancel and error separately:
createHandlerMap(addFoo, {
next(state, action) {},
complete(state, action) {},
})
createHandlerMap([addFoo.error, addFoo.cancel], (state, action) => { /* shared logic */ })
Hey @thebrodmann again! How do you create action creator in this case?
Just by using createActionCreator
in an object.
const addFoo = {
next: createActionCreator('NEXT'),
error: createActionCreator('ERROR'),
cancel: createActionCreator('CANCEL'),
complete: createActionCreator('COMPLETE'),
}
According to #2,
createHandlerMap
should be capable to handle optimistic action creators.Detailed Description
Yet, optimistic actions should be handled separately with multiple
createHandlerMap
call. So there would be a good point to reduce boilerplates. Although, cancel is not part of observer protocol but this type practically is important and should be handled in many cases (isFetching entity, etc.) in the reducers.Possible Implementation