redux-promise-middleware
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -20,4 +20,5 @@ 'use strict'; | ||
var types = action.types; | ||
var promise = action.payload; | ||
var _action$payload = action.payload; | ||
var promise = _action$payload.promise; | ||
var data = _action$payload.data; | ||
var PENDING = types[0]; | ||
@@ -32,3 +33,4 @@ var FULFILLED = types[1]; | ||
next({ | ||
type: PENDING | ||
type: PENDING, | ||
payload: data | ||
}); | ||
@@ -48,2 +50,3 @@ | ||
payload: error, | ||
error: true, | ||
type: REJECTED | ||
@@ -50,0 +53,0 @@ }); |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports['default'] = isPromise; | ||
function isPromise(value) { | ||
return value && typeof value.then === 'function'; | ||
if (value !== null && typeof value === 'object') { | ||
return value.promise && typeof value.promise.then === 'function'; | ||
} | ||
} | ||
module.exports = exports['default']; |
{ | ||
"name": "redux-promise-middleware", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Redux middleware for handling promises", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -21,3 +21,3 @@ # Redux Promise Middleware | ||
To use the middleware, dispatch a promise as the `payload` of the action and specify a `types` array. | ||
To use the middleware, dispatch a promise within the `payload` of the action and specify a `types` array. You may pass an optional `data` object. This is dispatched from the pending action and is useful for optimistic updates. | ||
@@ -27,3 +27,3 @@ The pending action is dispatched immediately. The fulfilled action is dispatched only if the promise is resolved, e.g., if it was successful; and the rejected action is dispatched only if the promise is rejected, e.g., if an error occurred. | ||
```js | ||
export function myAsyncActionCreator() { | ||
export function myAsyncActionCreator(data) { | ||
return { | ||
@@ -35,3 +35,6 @@ types: [ | ||
], | ||
payload: doSomethingAyncAndReturnPromise() | ||
payload: { | ||
promise: doSomethingAyncAndReturnPromise(data), | ||
data: data | ||
} | ||
}; | ||
@@ -38,0 +41,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
5059
56
45