redux-action-constants
Simple utils library for ReduxJS.
Instalation
redux-action-constants
- you can use npm
or yarn
package manager.
To install npm install redux-action-constants
yarn add redux-action-constants
Documentation
The redux-action-constants
library includes two functions: createActions
and createActionConstant
.
Below you can find the documentation for both functions.
createActions
function
The The function that creates actions from action-constants for dispatching.
createActions
function accept next arguments:
The Name | Type |
---|---|
actions | object |
createActionConstant
function
The The function that creates a nested action-constant.
createActionConstant
function accept next arguments:
The Name | Type |
---|---|
entrypoint | string |
schema | object |
Examples
1) The process of creating an action-constant.
; const ENTITIES = ; /** * The ENTITIES constant will have the next structure: * * { * REQUEST: "ENTITIES.REQUEST", * PROCESS: "ENTITIES.PROCESS", * SUCCESS: "ENTITIES.SUCCESS", * FAILURE: "ENTITIES.FAILURE", * HANDLER: undefined * * FETCH: { * REQUEST: "ENTITIES.FETCH.REQUEST", * PROCESS: "ENTITIES.FETCH.PROCESS", * SUCCESS: "ENTITIES.FETCH.SUCCESS", * FAILURE: "ENTITIES.FETCH.FAILURE", * HANDLER: undefined * * POSTS: { * REQUEST: "ENTITIES.FETCH.POSTS.REQUEST", * PROCESS: "ENTITIES.FETCH.POSTS.PROCESS", * SUCCESS: "ENTITIES.FETCH.POSTS.SUCCESS", * FAILURE: "ENTITIES.FETCH.POSTS.FAILURE", * HANDLER: undefined * }, * * COMMENTS: { * REQUEST: "ENTITIES.FETCH.COMMENTS.REQUEST", * PROCESS: "ENTITIES.FETCH.COMMENTS.PROCESS", * SUCCESS: "ENTITIES.FETCH.COMMENTS.SUCCESS", * FAILURE: "ENTITIES.FETCH.COMMENTS.FAILURE", * HANDLER: undefined * } * } * } */
2) The process of creating actions for dispatching.
;;;; { return null; } /** * Action handlers will be automatically created and targeted to the REQUEST handler. * * Warning! * Don't try to add the .REQUEST or the .SUCCESS or etc. in end of constant by yourself. * It's won't work. */const mapDispatchToProps = ; null mapDispatchToPropsMyClass;
3) Subscribe your reducer to the action-constant.
; const initialState = isLoading: false error: "" data: ; { const type content = action; const data error = content; }