redux-awaiter
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "redux-awaiter", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A Redux middleware for giving opportunities to await and receive actions in anywhere", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -12,3 +12,3 @@ # Redux Awaiter | ||
It's inspired by [Redux Saga](https://github.com/redux-saga/redux-saga/), but the problems they solved are totally different. | ||
It's inspired by [Redux Saga](https://github.com/redux-saga/redux-saga/), but the problems they solve are totally different. | ||
@@ -24,8 +24,10 @@ ## Example | ||
fetchUserList(); | ||
this.setState(state => ({ ...state, loading: true })); | ||
await take('RECEIVE_USER_LIST'); | ||
this.setState(state => ({ ...state, loading: false })); | ||
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 | ||
} | ||
render() { | ||
const { users } = this.props; // `users` is mapped from redux store | ||
const { loading } = this.state; | ||
return ( | ||
@@ -37,3 +39,3 @@ <Spin loading={loading}> | ||
</Spin> | ||
) | ||
); | ||
} | ||
@@ -96,3 +98,3 @@ } | ||
```typescript | ||
const take: <P, M = {}>(pattern: Pattern<P, M>) => Promise<Action<P, M>>; | ||
const take: <P = {}, M = {}>(pattern: Pattern<P, M>) => Promise<Action<P, M>>; | ||
``` | ||
@@ -110,4 +112,8 @@ | ||
`takeAllOf` receives an array of patterns as it single argument, and returns an array of promises. | ||
```typescript | ||
const takeAllOf: <P = {}, M = {}>(patterns: Pattern<P, M>[]) => Promise<Action<P, M>>[]; | ||
``` | ||
`takeAllOf` receives an array of patterns as its single argument, and returns an array of promises. | ||
Internally, `takeAllOf(patterns)` is the same with `Promise.all(patterns.map(take))`. | ||
@@ -123,4 +129,8 @@ | ||
`takeOneOf` receives an array of patterns as it single argument, and returns a promise. | ||
```typescript | ||
const takeOneOf: <P = {}, M = {}>(patterns: Pattern<P, M>[]) => Promise<Action<P, M>>; | ||
``` | ||
`takeOneOf` receives an array of patterns as its single argument, and returns a promise. | ||
Internally, `takeOneOf(patterns)` is the same with `Promise.race(patterns.map(take))`. | ||
@@ -127,0 +137,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22585
161