zashiki-promise-middleware
v1.0.23
Published
Redux Promise middleware for Zashiki
Downloads
17
Readme
zashiki-promise-middleware
Zashiki Promise Middleware
Zashiki Promise Middleware is a fork of the successful and popular Redux Promise Middleware v4.3.0 by Patrick Burtchaell, et al, and adapted for Zashiki Karakuri by Modern Poacher Limited.
For an introduction, you should review the Redux Promise Middleware package and its documentation.
Differences
When Zashiki Promise Middleware receives an action with a Promise payload, it dispatches two additional actions: a "pending" action, and then either a "fulfilled" or "rejected" action when the Promise is resolved. This is consistent with Redux Promise Middleware.
Zashiki Promise Middleware handles errors in "pending", "fulfilled" or "rejected" actions slightly differently to Redux Promise Middleware.
Any of the additional actions may encounter errors, but they will be caught and raised only when the Promise has been fulfilled or rejected:
- Promise Middleware should always dispatch a "pending" action, and either a "fulfilled" or "rejected" action
- An error in the "pending" or "fulfilled" actions should never dispatch a "rejected" action
- The error in a rejected Promise must be raised
- An error in any of the "pending", "fulfilled" or "rejected" actions must be raised
It is possible for a Promise to be fulfilled yet raise an error if any of the additional actions encounter an error; similarly, it is possible for a Promise to be rejected and for any of the additional actions to encounter an error, too.
To address this, Zashiki Promise Middleware extends and exports the Error
class as PromiseError
.
When a Promise is rejected, the middleware returns an Error
instance. When another error is encountered, the middleware returns a PromiseError
instance, and appends that other error as the property error
. In this way, all of the errors can be accessed as a chain on the instance raised to the caller.
Copyright © 2015 Patrick Burtchaell. Licensed with The MIT License (MIT).