reduxjs/redux-toolkit
### [`v1.3.5`](https://togithub.com/reduxjs/redux-toolkit/releases/v1.3.5)
[Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.3.4...v1.3.5)
This release adds the ability to cancel async thunks before execution, improves TS thunk types, and fixes a broken middleware option name change.
#### Changes
##### Async Thunk Cancellation
The `createAsyncThunk` API already had support for [signaling cancellation of in-progress requests via an `AbortController`](https://redux-toolkit.js.org/api/createAsyncThunk#canceling-while-running). However, there was no way to skip executing the payload creator callback itself, or skip dispatching the `pending` action.
We've added a `condition` option to `createAsyncThunk` that allows you to run checks before the payload creator is executed, and bail out of the thunk entirely if desired by returning `false`:
```js
const fetchUserById = createAsyncThunk(
'users/fetchByIdStatus',
async (userId, thunkAPI) => {
const response = await userAPI.fetchById(userId)
return response.data
},
{
condition: (userId, { getState, extra }) => {
const { users } = getState()
const fetchStatus = users.requests[userId]
if (fetchStatus === 'fulfilled' || fetchStatus === 'loading') {
// Already fetched or in progress, don't need to re-fetch
return false
}
}
}
)
```
##### Thunk Typing Improvements
We've updated the `createAsyncThunk` TS types to fix an issue when there is no thunk argument, and to make it easier to wrap `createAsyncThunk` in your own abstractions. See [#486](https://togithub.com/reduxjs/redux-toolkit/issues/486) / [#489](https://togithub.com/reduxjs/redux-toolkit/issues/489) for the issues and [#502](https://togithub.com/reduxjs/redux-toolkit/issues/502) / [#512](https://togithub.com/reduxjs/redux-toolkit/issues/512) for the updates.
##### Immutable Middleware Options
When we inlined the immutable check middleware, we ended up changing the `ignore` option name to `ignoredPaths`. We've added handling for `ignore` for backwards compatibility just in case anyone was relying on that. We've also better documented the options for the serializable check middleware. See [#491](https://togithub.com/reduxjs/redux-toolkit/issues/491), [#492](https://togithub.com/reduxjs/redux-toolkit/issues/492), and [#510](https://togithub.com/reduxjs/redux-toolkit/issues/510) .
#### Changelog
- allow to skip AsyncThunks using a condition callback ([@phryneas](https://togithub.com/phryneas) - [#513](https://togithub.com/reduxjs/redux-toolkit/issues/513))
- payloadCreator arg argument => asyncThunk arg type ([@phryneas](https://togithub.com/phryneas) - [#502](https://togithub.com/reduxjs/redux-toolkit/issues/502))
- export AsyncThunkPayloadCreator type ([@phryneas](https://togithub.com/phryneas) - [#512](https://togithub.com/reduxjs/redux-toolkit/issues/512))
- Update docs, add test, alias ignore->ignoredPaths ([@msutkowski](https://togithub.com/msutkowski) - [#492](https://togithub.com/reduxjs/redux-toolkit/issues/492))
- Add missing parameters to docs for serializable middleware ([@msutkowski](https://togithub.com/msutkowski) - [#510](https://togithub.com/reduxjs/redux-toolkit/issues/510))
Renovate configuration
:date: Schedule: At any time (no schedule defined).
:vertical_traffic_light: Automerge: Disabled by config. Please merge this manually once you are satisfied.
:recycle: Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
:no_bell: Ignore: Close this PR and you won't be reminded about this update again.
[ ] If you want to rebase/retry this PR, check this box
This PR contains the following updates:
1.3.4
->1.3.5
Release Notes
reduxjs/redux-toolkit
### [`v1.3.5`](https://togithub.com/reduxjs/redux-toolkit/releases/v1.3.5) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.3.4...v1.3.5) This release adds the ability to cancel async thunks before execution, improves TS thunk types, and fixes a broken middleware option name change. #### Changes ##### Async Thunk Cancellation The `createAsyncThunk` API already had support for [signaling cancellation of in-progress requests via an `AbortController`](https://redux-toolkit.js.org/api/createAsyncThunk#canceling-while-running). However, there was no way to skip executing the payload creator callback itself, or skip dispatching the `pending` action. We've added a `condition` option to `createAsyncThunk` that allows you to run checks before the payload creator is executed, and bail out of the thunk entirely if desired by returning `false`: ```js const fetchUserById = createAsyncThunk( 'users/fetchByIdStatus', async (userId, thunkAPI) => { const response = await userAPI.fetchById(userId) return response.data }, { condition: (userId, { getState, extra }) => { const { users } = getState() const fetchStatus = users.requests[userId] if (fetchStatus === 'fulfilled' || fetchStatus === 'loading') { // Already fetched or in progress, don't need to re-fetch return false } } } ) ``` ##### Thunk Typing Improvements We've updated the `createAsyncThunk` TS types to fix an issue when there is no thunk argument, and to make it easier to wrap `createAsyncThunk` in your own abstractions. See [#486](https://togithub.com/reduxjs/redux-toolkit/issues/486) / [#489](https://togithub.com/reduxjs/redux-toolkit/issues/489) for the issues and [#502](https://togithub.com/reduxjs/redux-toolkit/issues/502) / [#512](https://togithub.com/reduxjs/redux-toolkit/issues/512) for the updates. ##### Immutable Middleware Options When we inlined the immutable check middleware, we ended up changing the `ignore` option name to `ignoredPaths`. We've added handling for `ignore` for backwards compatibility just in case anyone was relying on that. We've also better documented the options for the serializable check middleware. See [#491](https://togithub.com/reduxjs/redux-toolkit/issues/491), [#492](https://togithub.com/reduxjs/redux-toolkit/issues/492), and [#510](https://togithub.com/reduxjs/redux-toolkit/issues/510) . #### Changelog - allow to skip AsyncThunks using a condition callback ([@phryneas](https://togithub.com/phryneas) - [#513](https://togithub.com/reduxjs/redux-toolkit/issues/513)) - payloadCreator arg argument => asyncThunk arg type ([@phryneas](https://togithub.com/phryneas) - [#502](https://togithub.com/reduxjs/redux-toolkit/issues/502)) - export AsyncThunkPayloadCreator type ([@phryneas](https://togithub.com/phryneas) - [#512](https://togithub.com/reduxjs/redux-toolkit/issues/512)) - Update docs, add test, alias ignore->ignoredPaths ([@msutkowski](https://togithub.com/msutkowski) - [#492](https://togithub.com/reduxjs/redux-toolkit/issues/492)) - Add missing parameters to docs for serializable middleware ([@msutkowski](https://togithub.com/msutkowski) - [#510](https://togithub.com/reduxjs/redux-toolkit/issues/510))Renovate configuration
:date: Schedule: At any time (no schedule defined).
:vertical_traffic_light: Automerge: Disabled by config. Please merge this manually once you are satisfied.
:recycle: Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
:no_bell: Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by WhiteSource Renovate. View repository job log here.