action-creator
A simple way to write function with context dependencies without context parameter
Get started
install
npm install action-creator
# or
yarn add action-creator
usage
Docs
1. bindActionCreators(object: actionCreators)(ctx) => object: actions
Param actionCreators
is a object contain action creators
, like:
it will return a function, and then pass param ctx
to this function. like:
const ctx = req: {} res: {} ctx
it will return a object contains {getIp, getUserName}
, now you can use getIp
directly.
2. connect(function: bindActionCreators(actionCreators))(beConnected) => function: wrappedActionCreator
An action is written like (..args) => (ctx, getAction) => {...}
, so if you want to use getAction
method,
you must connect
it with other actions you need. like:
const getName = { const getParentName = return + args1}// ... after do bindActionCreators(...)(ctx), you run getName() will// cause an Error 'getParentName is not a function' const connectedGetName = getName// this will be ok
License
MIT