redux-actions-class
Create action creators and types with minimal redundancy.
Install
npm i redux-actions-class --save
redux-actions or redux-act?
Why notThe benefits of this package compared to redux-actions is that you
don't have to manage a separate actionTypes
file; you get to define actions
on an orderly object literal and all your types and creators will live on just
one object. Just a matter of preference.
Considering redux-act, we achieve a similar goal of not having to declare or manage string constants, however, this package still enforces the SCREAMING_UNDERSCORE_CASING we are so used to.
In any case, both of those package offer some goodies beyond actions, like higher level reducer creators. For that I recommend coupling this package with redux-create-reducer - from the example in the redux reducing boilerplate section. As far as FSA enforcement goes, I got nothing but am open to PRs and suggestions.
Example
const actions = // use falsy value for actions with no payloads DISPLAY_COLORS: null // use string for single argument (like payload, if you use FSAs) ADD_COLOR: 'color' // use array for multiple arguments MIX_COLORS: 'color1' 'color2' // thunks work, too { return colors } // all keys from above spec will be added directly to your actions objectactionsDISPLAY_COLORS// => 'DISPLAY_COLORS' // all creators in camelCase form that can be dispatched are added tootypeof actionsdisplayColors// => 'function' // all types are also grouped together on the `types` field// (the values are identical)actionstypesDISPLAY_COLORS// => 'DISPLAY_COLORS' // likewise, all action creators are available through the creators key const mapDispatchToProps = { }
License
MIT