Gathering detailed insights and metrics for redux-action-creator
Gathering detailed insights and metrics for redux-action-creator
Gathering detailed insights and metrics for redux-action-creator
Gathering detailed insights and metrics for redux-action-creator
typesafe-actions
Typesafe Action Creators for Redux / Flux Architectures (in TypeScript)
redux-batched-actions
redux higher order reducer + action creator to reduce actions under a single subscriber notification
typescript-fsa
Type-safe action creator utilities
redux-resource-action-creators
Action creators for creating Redux Resource actions.
Reduce boilerplate code in your action creators and types
npm install redux-action-creator
Typescript
Module System
Node Version
NPM Version
70.4
Supply Chain
99.3
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
193,053
Last Day
71
Last Week
289
Last Month
1,327
Last Year
18,889
MIT License
21 Stars
32 Commits
1 Forks
1 Watchers
15 Branches
2 Contributors
Updated on Jul 25, 2020
Minified
Minified + Gzipped
Latest Version
3.0.0
Package Id
redux-action-creator@3.0.0
Unpacked Size
17.60 kB
Size
5.81 kB
File Count
5
NPM Version
6.2.0
Node Version
10.8.0
Cumulative downloads
Total Downloads
Last Day
108.8%
71
Compared to previous day
Last Week
0%
289
Compared to previous week
Last Month
-17.2%
1,327
Compared to previous month
Last Year
-44%
18,889
Compared to previous year
Reduce boilerplate code in your Redux action creators and types with support for normalizr, universal JavaScript, and Redux-first Router.
yarn add redux-action-creator
Use createTypes(types, [namespace])
to create action types with far less boilerplate.
types
is an array of strings designating the name of the action types and namespace
is an optional prefix to prevent name collisions.
Before:
1const types = { 2 CREATE_CAR: 'CAR_CREATE_CAR', 3 EDIT_CAR: 'CAR_EDIT_CAR', 4 EDIT_WHEELS: 'CAR_EDIT_WHEELS' 5};
After:
1import {createTypes} from 'redux-action-creator'; 2 3const types = createTypes(['CREATE_CAR', 'EDIT_CAR', 'EDIT_WHEELS'], 'CAR');
Asynchronous actions typically come in sets of three with the main action type along with a success and fail type.
Use the async(type)
helper to generate this set.
Before:
1const types = { 2 LOAD_CARS: 'CAR_LOAD_CARS', 3 LOAD_CARS_SUCCESS: 'CAR_LOAD_CARS_SUCCESS', 4 LOAD_CARS_FAIL: 'CAR_LOAD_CARS_FAIL', 5 ADD_CAR: 'CAR_ADD_CAR', 6 ADD_CAR_SUCCESS: 'CAR_ADD_CAR_SUCCESS', 7 ADD_CAR_FAIL: 'CAR_ADD_CAR_FAIL' 8};
After:
1import {createTypes, async} from 'redux-action-creator'; 2 3// use ES6 spread syntax to succinctly merge the returned asynchronous types 4const types = createTypes([ 5 ...async('LOAD_CARS'), 6 ...async('ADD_CAR') 7], 'CAR');
Synchronous action creators can be defined using the actionCreator(type [, propName1, propName2, ..., propNameX])
helper.
This will return a function that accepts the list of params as arguments and returns an action with the given type and arguments payload.
Before:
1var actions = { 2 createCar: function() { 3 return {type: 'CAR_CREATE_CAR'}; 4 }, 5 editCar: function({car}) { 6 return {type: 'CAR_EDIT_CAR', payload: { 7 car: car 8 }}; 9 } 10};
After:
1import {actionCreator} from 'redux-action-creator'; 2 3const actions = { 4 createCar: actionCreator(types.CREATE_CAR), 5 editCar: actionCreator(types.EDIT_CAR, 'car') 6};
Asynchronous action creators can be defined using the asyncActionCreator(type [, propName1, propName2, ..., propNameX], action|config)
helper.
If a function is passed as the last parameter, it will be treated as the asynchronous action that must return a promise, otherwise it can be a configuration object that accepts the following values:
action
: an asynchronous, promise-returning actionschema
: a normalizr schema which will parse the response before returningThe action given to asyncActionCreator
will eventually be called with the payload, any helpers
(see Helpers below) passed in, including the dispatch
function, and whatever
extra arguments as determined by the async middleware and the configuration of it. For example, if used with
redux-thunk, the action will be called with the payload, the helpers, the getState
function, and the extraArgument
if the middleware was created via the withExtraArgument
function.
Note: All other properties provided in config
apart from action
, client
, server
, and schema
will be appended
to all actions dispatched from the action creator enabling further customisation if needed.
Before:
1var actions = { 2 loadCars: function() { 3 return function(dispatch) { 4 dispatch({type: 'CAR_LOAD_CARS'}); 5 6 return get('/cars').then(function(response) { 7 dispatch({type: 'CAR_LOAD_CARS_SUCCESS', response: response}); 8 }).catch(function(err) { 9 dispatch({type: 'CAR_LOAD_CARS_FAIL', error: {message: err.message, code: err.code}}); 10 }); 11 }; 12 }, 13 addCar: function({electric, wheels}) { 14 return function(dispatch) { 15 var payload = {electric: electric, wheels: wheels}; 16 dispatch({type: 'CAR_ADD_CAR', payload: payload}); 17 18 return post('/cars', payload).then(function(response) { 19 dispatch({ 20 type: 'CAR_ADD_CAR_SUCCESS', 21 payload: payload, 22 response: normalize(response, new Schema('cars')) 23 }); 24 }).catch(function(err) { 25 dispatch({type: 'CAR_ADD_CAR_FAIL', payload: payload, error: {message: err.message, code: err.code}}); 26 }); 27 }; 28 } 29};
After:
1import {Schema} from 'normalizr'; 2import {asyncActionCreator} from 'redux-action-creator'; 3 4const actions = { 5 loadCars: asyncActionCreator(types.LOAD_CARS, () => get('/cars')), 6 addCar: asyncActionCreator(types.ADD_CAR, 'electric', 'wheels', { 7 action: payload => post('/cars', payload), 8 schema: new Schema('cars') 9 }) 10};
The action
returned by asyncActionCreator
accepts a payload object and also a helpers
object. This allows you to pass in any further functions required by the asynchronous action. For example, if using a library to help with forms such as reformist, quite often you'll require some form state to be modified depending on the state of the asynchronous action. Libraries such as reformist
provide functions to handle this such as setSubmitting
and setErrors
. These functions can be passed through as helpers to the asynchronous action to be used when the asynchronous task fails or succeeds. The dispatch
function will also be included in the helpers
object.
Instead of passing a single action to the asyncActionCreator
, you can instead pass a client
action and a
server
action and the appropriate function will be executed depending on the context in which it is run.
1const actions = { 2 loadCars: asyncActionCreator(types.LOAD_CARS, { 3 client: () => get('/cars'), 4 server: () => carService.loadCars(), 5 schema: new Schema('cars') 6 }) 7};
In this example, the client
action will be executed if run in the browser whereas the server
action will run on
the server when using a library such as redux-connect.
Note: if you have server-side only dependencies in your server
action that will create a troublesome client webpack build,
use the custom webpack universal-action-creator-loader to strip
the server
action from the action creator. All server-side dependencies must be require
d from within the server
function.
Asynchronous routes for Redux-first Router can be defined using the asyncRoute(type, path, action|config, [helpers])
helper.
It works similar to the asyncActionCreator
described above with the addition of the route path
and the helpers
object
containing any helper utilities the action may need to route correctly. The action given to asyncRoute
will eventually be
called with the payload, the dispatch
function, the getState
function, and finally the helpers
object if given.
asyncRoute
will return a route object of the form
1{ 2 [type]: { 3 path, 4 thunk, 5 ...rest 6 } 7}
where rest
is any further properties of config
apart from action
, client
, server
, and schema
that you need to
define the route.
For example, this can be used to set an isSecure
property on the route to signify that the route requires authorisation.
The returned route object can then be merged into the final routes map to be passed to Redux-first Router's connectRoutes
function.
1const routesMap = { 2 ROUTES_HOME: '/home', 3 ...asyncRoute('ROUTES_CARS', '/cars', () => get('/cars')), 4 ...asyncRoute('ROUTES_CAR', '/cars/:id', payload => get(`/cars/${payload.id}`)) 5}
Use createRouteTypes(types)
as a shortcut to creating types with 'ROUTES' as the namespace.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
47 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-12
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More