- I don't like the `@kea(...` because it's another bit of JS syntax I hadn't heard of before. Though I do like decorators in Python, I just feel like I have learned enough of JS syntax to be productive and they seem to keep adding unnecessary stuff.
- There is still duplication between the action names and the reducers. When using Redux I now always use these two functions:
function makeReducer(reducerObject) {
return (state, action) => {
if (Object.keys(reducerObject).includes(action.type)) {
return reducerObject[action.type](state, action.value)
}
return state
}
}
function makeActions(reducerObject) {
const actions = {}
Object.keys(reducerObject).forEach(name => {
actions[name] = value => {
return {type: name, value}
}
})
return actions
}
So I can just declare a single object of reducers and can infer the action names and creators from that e.g. const reducerObject = {
increment(state, value) {
return state + 1
},
decrement(state, value) {
return state - 1
}
}
const reducer = makeReducer(reducerObject)
const actions = makeActions(reducerObject)