Releases: pburtchaell/redux-promise-middleware
Release 3.1.0
The rejected parameter for a promise is now an error object. This change is not breaking.
// before
Promise.reject('foo').catch(error => {
console.log(error instanceof Error); // => false
});
// after
Promise.reject('foo').catch(error => {
console.log(error instanceof Error); // => true
});
// error object keys remain the same as 3.0.x
Promise.reject('foo').catch(({ reason, action }) => {
console.log(reason); // => 'foo'
});
Release 3.0.2
Removes
node_modules
from npm
Version 3.0.1
Removes:
docs/
folder from npmexamples/
folder from npm
Version 2.4.0
This is the first release under the @Prev dist tag on npm
breaking
- removes the feature of resolving custom actions in favour of resolving thunks for providing the same functionality.
- returns original promise from dispatch instead of a custom action
notes
if your original promise rejects, you can optionally catch it yourself from the caller of the action creator -- also if your promises have extra functionality (such as try or finally), this will be available from the caller.
Version 3.0.0
This release introduces some major changes to the functionality of the middleware:
First, the middleware returns a promise instead of the action.
// before
const foo = () => ({
type: 'FOO',
payload: {
promise: Promise.resolve('foo')
}
});
foo().action.promise.then(value => {
console.log(value); // => 'foo'
});
// after
const bar = () => ({
type: 'BAR',
payload: Promise.resolve('bar')
});
bar().then(({ value }) => {
console.log(value); // => 'bar'
});
Second, a new promise is created so .then()
and .catch()
work as expected.
// before
const foo = () => ({
type: 'FOO',
payload: {
promise: Promise.reject('foo')
}
});
foo().action.promise.then(
value => {
console.log(value); // => 'foo'
},
reason => {
// nothing happens
}
);
// after
const bar = () => ({
type: 'BAR',
payload: Promise.reject('bar')
});
bar().then(
({ value }) => {
// ...
},
({ reason }) => {
console.log(reason); // => 'bar'
}
);
const baz = () => ({
type: 'BAZ',
payload: new Promise((resolve, reject) => {
throw 'baz'
})
});
bar().catch(({ reason }) => {
console.log(reason) // => 'baz'
});
Third, promises can be explicitly or implicitly in the action object.
// before
const foo = () => ({
type: 'FOO',
payload: {
promise: Promise.resolve()
}
});
// after, with implicit promise as the value of the 'payload' property
const bar = () => ({
type: 'BAR',
payload: Promise.resolve()
});
Of course, if you prefer the explicit syntax, this still works. This syntax is also required for optimistic updates.
// after, but with explicit 'promise' property and 'data' property
const bar = () => ({
type: 'BAZ',
payload: {
promise: Promise.resolve(),
data: ...
}
});
Fourth, thunks are no longer bound to the promise. If you are chaining actions with Redux Thunk, this is critical change.
// before, with Redux Thunk
const foo = () => ({
type: 'FOO',
payload: {
promise: new Promise((resolve, reject) => {
...
}).then(
value => (action, dispatch) => {
// handle fulfilled
dispatch(someSuccessHandlerActionCreator());
},
reason => (action, dispatch) => {
// handle rejected
dispatch(someErrorHandlerActionCreator());
}
)
}
});
// after, with Redux Thunk
const bar = () => {
return (dispatch, getState) => {
return dispatch({
type: 'FOO',
payload: Promise.resolve('foo')
}).then(
({ value, action }) => {
console.log(value); // => 'foo'
console.log(action.type); // => 'FOO_FULFILLED'
dispatch(someSuccessHandlerActionCreator());
},
({ reason, action }) => {
// handle rejected
dispatch(someErrorHandlerActionCreator());
}
);
};
};
Version 2.2.4
This release binds the first argument of any function given to Promise.resolve
to a partial action object so one can access the original meta
and an appropriate type
within their thunk.
Version 2.2.3
Fixes a critical bug in version 2.2.2. 🔥 🚒
Please note that version 2.2.2 has also been deprecated on npm.
Version 2.2.2
With the previous release, dispatched actions are set through the entire stack of middleware.
const actionCreator = () => ({
type: 'EXAMPLE_TYPE',
payload: {
promise: Promise.resolve({
type: 'RESOLVED_ACTION'
payload: ...
})
}
});
However, this middleware does not check to see if the resolved or rejected parameter is a function. This release adds a check for thunk /function before resolving or rejecting as payload.
For example, now the following will also work:
const actionCreator = () => ({
type: 'EXAMPLE_TYPE',
payload: {
promise: Promise.resolve((dispatch, getState) => {
dispatch({ type: 'RESOLVED_ACTION', payload: '' })
dispatch(someActionCreatorThatMaybeUpdatesTheRoute())
doSomethingNaughtyAfterDispatchingEverything(getState())
})
}
});
This is not a breaking change.
Version 2.2.1
Instead of calling next()
to dispatch rejected and fulfilled actions, the middleware now recalls dispatch()
and dispatches entirely new actions. This is not a breaking change.
Version 2.2.0
Breaking Changes 🔥
- In the case that the promise resolves
null
, the middleware will dispatch an empty object instead of dispatchingnull
.