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

redux-awaiter

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-awaiter - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

package.json
{
"name": "redux-awaiter",
"version": "0.0.5",
"version": "0.0.6",
"description": "A Redux middleware for giving opportunities to await and receive actions in anywhere",

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

@@ -10,2 +10,4 @@ # Redux Awaiter

*[Local state is fine](https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367)*.
Redux Awaiter is designed to await and receive Redux actions in React components and help us manage local state conveniently.

@@ -17,2 +19,4 @@

We can use Redux Awaiter and `async/await` to pause execution until an expected action has been dispatched.
```javascript

@@ -25,5 +29,7 @@ class UserListView extends React.PureComponent {

fetchUserList();
this.setState(state => ({ ...state, loading: true })); // start loading
await take('RECEIVE_USER_LIST'); // reducers will update `users` in redux store
this.setState(state => ({ ...state, loading: false })); // receive data, stop loading
this.setState(state => ({ ...state, loading: true }));
// start loading, until RECEIVE_USER_LIST has been dispatched
await take('RECEIVE_USER_LIST');
// reducers may update `users` in redux store, stop loading
this.setState(state => ({ ...state, loading: false }));
}

@@ -73,3 +79,3 @@

A pattern is to determine whether an action is matching with another.
A pattern is to determine whether an action is matching.

@@ -80,2 +86,4 @@ ```typescript

`object` pattern is not supported, use a function instead.
### API

@@ -115,3 +123,3 @@

`takeAllOf` receives an array of patterns as its single argument, and returns a Promise which contains an array of actions correspond to patterns.
`takeAllOf` receives an array of patterns as its single argument, and returns a Promise which contains an array of actions corresponding to patterns.

@@ -132,3 +140,3 @@ Internally, `takeAllOf(patterns)` is the same with `Promise.all(patterns.map(take))`.

`takeOneOf` receives an array of patterns as its single argument, and returns a Promise which contains the first action matched with one of patterns.
`takeOneOf` receives an array of patterns as its single argument, and returns a Promise which contains the first action matching with one of patterns.

@@ -146,3 +154,3 @@ Internally, `takeOneOf(patterns)` is the same with `Promise.race(patterns.map(take))`.

You might not need `takeOneOf`:
You might not need `takeOneOf`.
```javascript

@@ -149,0 +157,0 @@ const { type } = await take(/^FETCH_USER/);

@@ -6,3 +6,3 @@ import { Middleware } from 'redux';

export const createAwaiterMiddleware = (): Middleware => () => next => (action) => {
awaiters.consume(action as any); // cast AnyAction to standard Action<T>
awaiters.consume(action as any); // cast AnyAction to standard Action<P, M>
return next(action);

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

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