|
|
|
|
|
by the_gipsy
3024 days ago
|
|
It's too much boilerplate. In my current project, I have to describe one action 7 times: 1. The constant var `const ACTION_NAME = ...`
2. The constant's value `... = Symbol('ACTION_NAME')`
3. The "action creator" function `const doAction = arg => ...` (extra creativity to add a verb here?)
4. The action creator's return struct: `... => ({ type: ACTION_NAME, payload: arg })`
5. The reducer switch clause `case ACTION NAME:`
6. The container action to callback mapping `onClickThing: dispatch(doAction(42))`
7: The jsx/component calling the callback `onClick={onClickThing}`
compare that to The Elm Architecture, from which redux is inspired AFAIK. An action only needs to be referenced in 3 places: 1. The tag on the Msg type: `type Msg = ActionName arg | ...`
2. The `case` pattern matcher in the update function
3. The view sending said Msg/action
|
|