fsaction
Flux Standard Action object creator.
A little shorthand to help creating flux standard action objects.
Installation
npm install fsaction
Usage
; todeep;todeep;todeep;todeep;)todeep;
API
fsaction(type: string, payload?: any, meta?: any) : object
When payload
or meta
are functions, they - and any functions they return - will be called until something else than a function is returned.
)todeep;
payload
or meta
functions receive action object as their 1st argument.
payloadCreator(action: object) : payload | payloadCreator
In payload()
, this object only has a type
property.
In meta()
, this object has type
, maybe payload
, and maybe error
properties.
You should treat this object as read only, as that is the resulting FSA object, and modifying it in non-standard way will break FSA compliance.
fsaction.error(type: string, payload?: any, meta?: any) : object
Forces error
flag on the resulting action object.
Aliases: fsaction.err()
, fsaction.e()
redux-actions?
Why notMy actions are usually complex and async, and I prefer them returning a promise instead of an object with promise on its payload
property, so combined with redux-thunk
and redux-promise
I can do stuff like this:
const deleteUser = async { await ; return ;};
If deleteUserData()
was created with redux-actions' createAction()
, I'd have to do:
await payload
which just feels weird to me, and doesn't seem right ™.
In other words, fsaction provides more control over how your actions look like, and how they work. And you can easily use an arrow to replace the redux-actions' createAction()
:
const payloadCreator = amount; // redux-actions' `createAction()`const increment = ; // fsactionconst increment = ;
License
ISC License (ISC)