Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-combine-actions

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-combine-actions - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

lib/index.js

@@ -6,3 +6,3 @@ "use strict";

function isArrayOfFunctions(array) {
return Array.isArray(array) && array.every(function (item) {
return Array.isArray(array) && array.length > 0 && array.every(function (item) {
return item instanceof Function;

@@ -9,0 +9,0 @@ });

{
"name": "redux-combine-actions",
"version": "0.1.1",
"version": "0.1.2",
"description": "Redux middleware for combining actions",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -6,3 +6,3 @@ # Redux Combine Actions

This is a Redux middleware that allows you to easy combine actions and dispatch them sequentially.
This is a Redux middleware that allows you to easy combine async actions and dispatch them either sequentially or in parallel.

@@ -17,12 +17,27 @@ ### Installation

Manual TBD
To enable redux-combine-actions use applyMiddleware()
```js
import { createStore, combineReducers, applyMiddleware } from 'redux';
import combineActionsMiddleware from 'redux-combine-actions';
import * as reducers from './reducers';
let createStoreWithMiddleware = applyMiddleware(combineActionsMiddleware)(createStore);
let reducer = combineReducers(reducers);
let store = createStoreWithMiddleware(reducer);
```
Simple usage
To use the middleware, you action creator must return action with the following fields:
- `types` - An array of action types in the next notation: [PENDING, SUCCESS, ERROR], where PENDING action is dispatched immediately, SUCCESS action is dispatched only if all child actions were executed successfully and ERROR action is dispatched only if an error occurred.
- `payload` - An array of [action creators](http://gaearon.github.io/redux/docs/basics/Actions.html#action-creators). This field must contain set of functions which shall be dispatched. For example, it can be [ordinary action creators](#simple-usage), or action creators that return a [promise](#with-promises) (see [redux-promise](https://github.com/acdlite/redux-promise) or [redux-promise-middleware](https://github.com/pburtchaell/redux-promise-middleware)), in this case, you can specify `sequence` option.
- `sequence` - Specifies actions sequence. If `true` - dispatch array of action creators in sequential order, else - dispatch in parallel.
The middleware returns a promise to the caller and a [FSA](https://github.com/acdlite/flux-standard-action) compliant action for both SUCCESS and ERROR action types.
### Simple usage
```js
export function addTodo(text) {
return { type: types.ADD_TODO, text };
return { type: ADD_TODO, text };
}

@@ -40,12 +55,20 @@

'COMBINED_ACTION_START',
'COMBINED ACTION_SUCCESS',
'COMBINED ACTION_ERROR'
'COMBINED_ACTION_SUCCESS',
'COMBINED_ACTION_ERROR'
],
// Pass actions in array
payload: [addTodo.bind(text), increment]
payload: [addTodo.bind(null, text), increment]
};
}
// Dispatch action
store.dispatch(addTodoAndIncrement({text:'Dispatch combined action'}));
```
This will dispatch actions in the following sequence:
*`COMBINED_ACTION_START`* > *`ADD_TODO`* > *`INCREMENT_COUNTER`* > *`COMBINED_ACTION_SUCCESS`*
### With promises
Using in combination with [redux-promise-middleware](https://github.com/pburtchaell/redux-promise-middleware).

@@ -60,3 +83,5 @@ ```js

],
payload: api.getProvidersAsync()
payload: {
promise: api.getProvidersAsync()
}
};

@@ -72,3 +97,5 @@ }

],
payload: api.getSubscribersAsync()
payload: {
promise: api.getSubscribersAsync()
}
};

@@ -96,4 +123,12 @@ }

This will dispatch actions one after another:
*`DATABASE_FETCH_PENDING`* > *`PROVIDERS_GET_PENDING`* > *`PROVIDERS_GET_SUCCESS`* > *`SUBSCRIBER_GET_PENDING`* > *`SUBSCRIBER_GET_SUCCESS`* > *`DATABASE_FETCH_SUCCESS`*
If you set `sequence` to `false` then all child actions will be dispatched in parallel:
*`DATABASE_FETCH_PENDING`* > *`PROVIDERS_GET_PENDING`* > *`SUBSCRIBER_GET_PENDING`* > *`PROVIDERS_GET_SUCCESS`* > *`SUBSCRIBER_GET_SUCCESS`* > *`DATABASE_FETCH_SUCCESS`*
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc