Gathering detailed insights and metrics for redux-async-action-reducer
Gathering detailed insights and metrics for redux-async-action-reducer
Gathering detailed insights and metrics for redux-async-action-reducer
Gathering detailed insights and metrics for redux-async-action-reducer
npm install redux-async-action-reducer
Typescript
Module System
Node Version
NPM Version
66.3
Supply Chain
98.2
Quality
74.2
Maintenance
100
Vulnerability
97.9
License
TypeScript (100%)
Total Downloads
3,118
Last Day
9
Last Week
9
Last Month
22
Last Year
210
1 Stars
35 Commits
5 Branches
1 Contributors
Updated on Jul 09, 2017
Minified
Minified + Gzipped
Latest Version
0.5.2
Package Id
redux-async-action-reducer@0.5.2
Size
55.64 kB
NPM Version
4.2.0
Node Version
7.10.0
Cumulative downloads
Total Downloads
Last Day
0%
9
Compared to previous day
Last Week
200%
9
Compared to previous week
Last Month
-54.2%
22
Compared to previous month
Last Year
29.6%
210
Compared to previous year
1
6
A simple wrapper for creating redux actions and reducers. The library makes creating and handling both asynchronous and synchronous actions easier. It's completely written, with type safety in mind, with typescript.
Action creator can either create a synchronous action or an asynchronous action. For more general information about actions refer to redux docs
Asynchronous Actions are actions that will invoke an api and are designed to work with libraries like redux-thunk or redux-saga.
Traditional way of creating asynchronous action
1import { api } from '../api' 2import { ACTION_TYPE, STARTED, SUCCEEDED, FAILURE } from '../constants' 3 4const action = (dispatch) => { 5 (request) => { 6 dispatch({ type: ACTION_TYPE, status: STARTED, request }) 7 api(request).then((response) => { 8 dispatch({ type: ACTION_TYPE, status: SUCCEEDED, request, response}) 9 }).catch((error)=>{ 10 dispatch({ type: ACTION_TYPE, status: FAILURE, request, error}) 11 }) 12 } 13}
can be replaced with single line (or two lines)
1import { createAsyncAction } from 'redux-async-action-reducer' 2import { api } from '../api' 3import { ACTION_TYPE } from '../constants' 4 5 6const action = createAsyncAction(ACTION_TYPE, api) 7//with typescript 8const action = createAsyncAction<ACTION_TYPE, ApiResponseObj>(ACTION_TYPE, api)
A synchronous action instantly returns an Action object (an object with type attribute and a string type value)
Traditional way of creating synchronous action
1import { ACTION_TYPE } from '../constants' 2const action = (request) => ({ 3 type: ACTION_TYPE, request // payload is most common used key. 4})
can be replaced with single line
1import { createSimpleAction } from 'redux-async-action-reducer' 2import { ACTION_TYPE } from '../constants' 3 4const action = createSimpleAction(ACTION_TYPE); 5//with typescript 6const action = createSimpleAction<ACTION_TYPE, RequestType>(ACTION_TYPE); 7
Use of request and response is convenient and consistent across synchronous and asynchronous actions rather than using payload for request
Reducer can also be either synchronous or asynchronous. Asynchronous reducer need an asynchronous action while synchronous reducer can act up on both synchronous and asynchronous actions. For more general information about reducers refer to redux docs
Traditional way of creating a reducer is using switch cases
1const reducer = (state = initialState, action){ 2 switch(action.type){ 3 //All synchronous and asynchronous reducers goes here 4 } 5}
would be replaced with something like this
1import { createReducer } from 'redux-async-action-reducer'; 2const reducer = createReducer(initialState, 3 [/*list of synchronous reducer*/], [/*list of asynchronous reducers*/] 4)
NOTE: As a side effect a synchronous reducer acting upon asynchronous action will be called 3 times. Future version will support synchronous action status reducer
Traditional way of creating asynchronous reducer
1import { ACTION_TYPE, STARTED, SUCCEEDED, FAILURE } from '../constants' 2 3const actionTypeReducer = (state, action){ 4 if(action.status === STARTED){ 5 return {...state, working: true, failure: false, completed: false, started: new Date(), finished: undefined} 6 } else if(action.status === SUCCEEDED){ 7 return {...state, working: false, failure: false, completed: true, store: action.response} 8 } else if( action.status === FAILURE){ 9 return {...state, working: false, failure: true, completed: false, finished: new Date()} 10 } 11 return state 12} 13const reducer = (state = initialState, action) => { 14 switch(action.type){ 15 case 'ACTION_TYPE': state = actionTypeReducer(state, action) 16 // 17 // more switch cases for reducers 18 // 19 } 20 return state 21}
can be replaced with
1import { createReducer, asyncReducer } from 'redux-async-action-reducer'; 2 3import { ACTION_TYPE } from '../constants' 4const reducer = createReducer(initialState, [/*synchronous reducers*/], 5 [asyncReducer(ACTION_TYPE), /*more reducers*/] 6) 7
Traditional way of creating synchronous reducer
1import { ACTION_TYPE } from '../constants' 2 3const actionTypeReducer = (state, action){ 4 return {...state, request: action.request} 5} 6const reducer = (state = initialState, action) => { 7 switch(action.type){ 8 case 'ACTION_TYPE': actionTypeReducer(state, action) 9 // 10 // more switch cases for reducers 11 // 12 } 13}
can be replaced with
1import { createReducer, syncReducer } from 'redux-async-action-reducer'; 2import { ACTION_TYPE } from '../constants' 3 4const reducer = createReducer(initialState, 5 [syncReducer(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 6)
When a store is an array object we can use array reducer. It supports CLUD (Load instead of Read) apis. Both synchronous and asynchronous support full CLUD operations on array reducers.
Adding an element into the array
1import { arraySyncCreateReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arraySyncCreateReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will add request object into array
1import { arrayAsyncCreateReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arrayAsyncCreateReducer<ACTION_TYPE, RequestType, ResponseType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will add response object into array
NOTE: If your create API does not give response object which need to be added, change the response object to what ever you want to add
Load all elements into the array
1import { arraySyncLoadReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arraySyncLoadReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will load RequestType[] into store
1import { arrayAsyncLoadReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arrayAsyncLoadReducer<ACTION_TYPE, RequestType, ResponseType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will load ResponseType[] into store
Load all elements into the array
1import { arraySyncUpdateReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arraySyncUpdateReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will need a request array with 2 elements with first element original object and second object what the values to be updated to 7//eg. the action would look something like this 8import { createSimpleAction } from 'redux-async-action-reducer' 9const action = createSimpleAction<ACTION_TYPE, RequestType>(ACTION_TYPE); 10const updateArray: RequestType[] = [originalObject, updatedObject] 11action(updateArray) //store.dispatch(action(updateArray)) 12
1import { arrayAsyncUpdateReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arrayAsyncLoadReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This expect action to dispatch request with an array [originalObject, updatedObject] while response will give you the updatedObject. 7import { createAsyncAction } from 'redux-async-action-reducer' 8import { api } from '../api' 9const action = createAsyncAction<ACTION_TYPE, RequestType>(ACTION_TYPE, api); 10const updateArray: RequestType[] = [originalObject, updatedObject] 11action(updateArray) //store.dispatch(action(updateArray))
Load all elements into the array
1import { arraySyncDeleteReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arraySyncDeleteReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// This will load RequestType[] into store
1import { arrayAsyncDeleteReducer } from 'redux-async-action-reducer' 2 3const reducer = createReducer(initialState, 4 [arrayAsyncDeleteReducer<ACTION_TYPE, RequestType>(ACTION_TYPE), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6// Action need to be invoked with request object of the element which needs to be removed from the array
Status reducer is reducer who acts upon on status change of all or a list of action types. Traditional way of doing it
1import { ACTION_TYPE, STARTED, SUCCEEDED, FAILURE } from '../constants' 2 3const actionTypeReducer = (state, action){ 4 //for all actions remove the following line 5 if(['ACTION_TYPE1','ACTION_TYPE2', 'ACTION_TYPE3'/*etc*/].indexOf(action.type) === -1) { 6 return state 7 } else if(action.status === STARTED){ 8 return {...state, working: true, failure: false, completed: false, started: new Date(), finished: undefined} 9 } else if(action.status === SUCCEEDED){ 10 return {...state, working: false, failure: false, completed: true, store: action.response} 11 } else if( action.status === FAILURE){ 12 return {...state, working: false, failure: true, completed: false, finished: new Date()} 13 } else { 14 return state 15 } 16} 17const reducer = (state = initialState, action) => { 18 actionTypeReducer(state, action) 19 switch(action.type){ 20 // 21 // more switch cases for reducers 22 // 23 } 24}
can be replaced with
1import { arrayAsyncLoadReducer } from 'redux-async-action-reducer' 2type ACTION_TYPE = 'ACTION_TYPE1' | 'ACTION_TYPE2' | 'ACTION_TYPE3' //eg only 3const reducer = createReducer(initialState, 4 [asyncReducer<ACTION_TYPE[], RequestType, ResponseType>(['ACTION_TYPE1','ACTION_TYPE2','ACTION_TYPE3']), /*more reducers*/],[/*asynchronous reducers if needed*/] 5) 6 7//or all for all actions 8const reducer = createReducer(initialState, 9 [asyncReducer<ACTION_TYPE, RequestType, ResponseType>(), /*more reducers*/],[/*asynchronous reducers if needed*/] 10) 11
The library takes starting inspiration from redux-actions.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
58 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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