I saw an argument for separating actions from reducers because they are many-to-many.
I do not think this is really applicable in Redux. Since there is only 1 data warehouse, the actions for reducers must be 1-to-many.
Typically, reducers are applied to a specific change in a particular data warehouse.
MY_ACTION = "MY_ACTION" function reducer(state, action) { switch(action.type) { case MY_ACTION:
We can combine several reducers with combineReducers , so why not define a handler for the action with the action itself.
for instance
class Action { constructor(type) { this.type = type this.handlers = [] } add_handler(handler) { this.handlers += handler } get_reducer() { reducer = combineReducers(this.handlers) return (state, action) => { if(action.type == this.type) { return reducer(state, action) } return state } } }
With the “ducks” pattern, we end up putting the main gears in the same module as the action declaration.
Is there any reason for reducers + actions to be separated with reduction?
source share