myreduxtypes
myreduxtypes is a lightweight package which allows you to autogenerate redux types
Features!
- Generate types for CRUD operation /CREATE/REMOVE/FIND/GET/PATCH and plus SET/LOADING
- Generate customised types for some specific needs
Usage
myreduxtypes requires Node.js v4+ to run.
Install the dependencies and devDependencies and start the server.
$ cd my-app$ npx create-react-app .$ npm i redux react-redux --save$ npm i myreduxtypes --save$ npm start
In Redux Module
First you need to import package\
For common js
const
For ES6 and higher
import {autoTypeGen, customTypeGen,simpleTypeGen} from 'myreduxtypes'
For autoTypeGen
export const [types, actions] = autoTypeGen
And with only this line of code you are having CRUD operation ready types and actions
Types
Actions
{
create_start: [Function (anonymous)],
create_success: [Function (anonymous)],
create_failed: [Function (anonymous)],
loading: [Function (anonymous)],
set_current: [Function (anonymous)],
patch_start: [Function (anonymous)],
patch_success: [Function (anonymous)],
patch_failed: [Function (anonymous)],
remove_start: [Function (anonymous)],
remove_success: [Function (anonymous)],
remove_failed: [Function (anonymous)],
get_start: [Function (anonymous)],
get_success: [Function (anonymous)],
get_failed: [Function (anonymous)],
find_start: [Function (anonymous)],
find_success: [Function (anonymous)],
find_failed: [Function (anonymous)]
}
Each action function accepts two arguments optionally /data and route
actions.create_start(data,'/')
output====>
{ type: 'CREATE_PRODUCT_START', payload: data, route: '/' }
Custom types with myreduxtypes
import
You will get types and actions for each argument provided to autoTypeGen
More
To have both CRUD and optional types you need to provide boolien argument a the end by default its false
import
Package will generate
For Custom types
const
- Types
MODAL_OPEN: 'MODAL_OPEN' MODAL_CLOSE: 'MODAL_CLOSE' MODAL_TOGGLE: 'MODAL_TOGGLE'
- Actions
modal_open: Function anonymous modal_close: Function anonymous modal_toggle: Function anonymous
- You cann pass arguments optionally
==================================