(no title)
jamesisaac | 8 years ago
1. You can use strings for action types, no more need to import constants.
2. No need for action creators for simple actions, you can just create the action object inline and Flow will validate its shape.
3. You can be sure that reducers are unpacking properties that actually exist from the actions.
In other words, your example could simply be:
// types.js
type Action =
| { type: 'ADD_TODO', text: string }
// TodoList.js
dispatch({ type: 'ADD_TODO', text })
...and Flow would confirm at 'compile time' that it matches the contract dispatch expects.This approach has scaled up extremely well for me and no longer feels verbose.
nathan_f77|8 years ago
And then I found myself writing action creators on purpose, not because I saw it in some tutorial, but because it actually does remove some duplication.
This was also missing from my education for a long time: https://github.com/acdlite/flux-standard-action#actions
I had no idea why I was using a "payload" key, instead of just putting all the values in the top-level object. But this convention makes a lot of sense now.