A human-friendly advanced standard for Redux action objects.
$ npm install --save redux-hyper-action
Prudently extends the meta
property of Flux Standard Action.
Action Instance
= Action Type
+ Action Payload
+ (Optional)Action Time
Action Id
= generateActionId(Action Instance)
Totally compatible with Flux Standard Action.
type: string error: boolean payload: PlainValue (SHOULD NOT be
Error
) meta: (SeeMeta
below)
type PlainPrimitive = undefined | null | string | number | boolean;
type PlainObject = {[k in string]?: PlainValue};
type PlainArray = PlainValue[];
type PlainValue = PlainPrimitive | PlainObject | PlainArray;
Always has a string
value redux-hyper-action
.
It's used to distinguish Redux Hyper Action
s from others.
A UUID string.
See Convention
above.
Optional.
A UUID string, but parent's.
Async actions only.
started
| finished
Async actions only.
Integer between 0-100.
Create time in ISO string.
Optional.
Update time in ISO string.
Boolean.
Boolean.
Usage example:
import {isValidAction} from 'redux-hyper-action';
isValidAction({type: 'foo', payload: 'bar'})); // false
(action: any) => boolean
(type: string, payload?: Payload, uniq?: boolean) => string
(type: string, payload?: Payload, option?: Option) => Action
(type: string, payload?: Payload) => Action
(type: string, payload?: Payload) => Action
(action: Action) => string
(action: Action) => string
(action: Action) => false
(action: Action) => boolean
(action: Action) => boolean
(action: Action) => boolean
(action: Action) => boolean
(action: Action) => boolean
(payload: Payload, progress?: number) => (action: Action) => Action
(payload: Payload) => (action: Action) => Action
(error: Error) => (action: Action) => Action
(parent: Action) => (child: Action) => Action
(parent: Action) => (child: Action) => boolean
There is one exception for error handling (but not a conflict).
The payload
field can't be an Error
anyway, while keeping error
field boolean
type.
Reason:
- Write Actions Using the Flux Standard Action Convention
- Do Not Put Non-Serializable Values in State or Actions
There is only one way to create an action indicating Error
using redux-hyper-action
.
import {createAsyncAction, failWith} from 'redux-hyper-action';
const action = createAsyncAction('type', 'payload');
const actionHasError = failWith('any contents');
What about sync actions created by createAction
?
Sync actions do not have their own transitional state, so they can not be updated.
If you want, just fill the payload field with any data describing the "error", and create branch new action with createAction
.
In the past, redux actions in this form were used to describe transient async process, which triggered by user interactions.
But think about this,
How many interactions were happened when the user clicked on a button?
In fact, from the user's point of view, the transient async progress is behind the scenes process.
In other words, tracking these states is implemetation detail of the system under the UI layer.
But most of the time, we are using multiple actions to describe single user event, although not all.
For the consistency of mental models with actual user interacitons, redux-hyper-action
chooses single action object to describing that transient async process.
It will be easier and more natural to understand action manipulations in the UI layer in this way.