Skip to content

Commit 791966b

Browse files
committed
Update to Redux core v5 rc1 and replace isAction/isPlainObject with core counterparts
1 parent 1168d6f commit 791966b

File tree

11 files changed

+22
-107
lines changed

11 files changed

+22
-107
lines changed

docs/api/matching-utilities.mdx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Redux Toolkit exports several type-safe action matching utilities that you can l
1313

1414
### General Purpose
1515

16-
- [`isAction`](#isaction) - returns true if a passed value is a standard action object, with a type string
1716
- [`isAllOf`](#isallof) - returns true when **all** conditions are met
1817
- [`isAnyOf`](#isanyof) - returns true when **at least one of** the conditions are met
1918

@@ -27,16 +26,6 @@ All these matchers can either be called with one or more thunks as arguments, in
2726
- [`isRejected`](#isrejected) - accepts one or more action creators and returns true when all match
2827
- [`isRejectedWithValue`](#isrejectedwithvalue) - accepts one or more action creators and returns true when all match
2928

30-
## `isAction`
31-
32-
A type guard that takes an unknown variable, and returns `true` if it's a standard Redux action with a string `type` property.
33-
34-
:::caution
35-
36-
As of Redux 5.0, action types are _required_ to be a string.
37-
38-
:::
39-
4029
## `isAllOf`
4130

4231
A higher-order function that accepts one or more of:

packages/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
],
115115
"dependencies": {
116116
"immer": "^10.0.3",
117-
"redux": "^5.0.0-rc.0",
117+
"redux": "^5.0.0-rc.1",
118118
"redux-thunk": "^3.0.0-rc.0",
119119
"reselect": "^5.0.0-beta.1"
120120
},

packages/toolkit/src/configureStore.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import type {
77
Store,
88
UnknownAction,
99
} from 'redux'
10-
import { applyMiddleware, createStore, compose, combineReducers } from 'redux'
10+
import {
11+
applyMiddleware,
12+
createStore,
13+
compose,
14+
combineReducers,
15+
isPlainObject,
16+
} from 'redux'
1117
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
1218
import { composeWithDevTools } from './devtoolsExtension'
1319

14-
import isPlainObject from './isPlainObject'
1520
import type {
1621
ThunkMiddlewareFor,
1722
GetDefaultMiddleware,

packages/toolkit/src/createAction.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { Action } from 'redux'
1+
import { isAction } from 'redux'
22
import type {
33
IsUnknownOrNonInferrable,
44
IfMaybeUndefined,
55
IfVoid,
66
IsAny,
77
} from './tsHelpers'
88
import { hasMatchFunction } from './tsHelpers'
9-
import isPlainObject from './isPlainObject'
109

1110
/**
1211
* An action with a string type and an associated payload. This is the
@@ -285,17 +284,6 @@ export function createAction(type: string, prepareAction?: Function): any {
285284
return actionCreator
286285
}
287286

288-
/**
289-
* Returns true if value is a plain object with a `type` property.
290-
*/
291-
export function isAction(action: unknown): action is Action<string> {
292-
return (
293-
isPlainObject(action) &&
294-
'type' in action &&
295-
typeof (action as Record<'type', unknown>).type === 'string'
296-
)
297-
}
298-
299287
/**
300288
* Returns true if value is an RTK-like action creator, with a static type property and match method.
301289
*/

packages/toolkit/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export type { DevToolsEnhancerOptions } from './devtoolsExtension'
4242
export {
4343
// js
4444
createAction,
45-
isAction,
4645
isActionCreator,
4746
isFSA as isFluxStandardAction,
4847
} from './createAction'
@@ -157,8 +156,6 @@ export type {
157156

158157
export { nanoid } from './nanoid'
159158

160-
export { default as isPlainObject } from './isPlainObject'
161-
162159
export type {
163160
ListenerEffect,
164161
ListenerMiddleware,

packages/toolkit/src/isPlainObject.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/toolkit/src/listenerMiddleware/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Action, Dispatch, MiddlewareAPI, UnknownAction } from 'redux'
2+
import { isAction } from 'redux'
23
import type { ThunkDispatch } from 'redux-thunk'
3-
import { createAction, isAction } from '../createAction'
4+
import { createAction } from '../createAction'
45
import { nanoid } from '../nanoid'
56

67
import type {

packages/toolkit/src/serializableStateInvariantMiddleware.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import isPlainObject from './isPlainObject'
21
import type { Middleware } from 'redux'
2+
import { isAction, isPlainObject } from 'redux'
33
import { getTimeMeasureUtils } from './utils'
4-
import { isAction } from './createAction'
54

65
/**
76
* Returns true if the passed value is "plain", i.e. a value that is either

packages/toolkit/src/tests/createAction.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createAction, isAction, isActionCreator } from '@reduxjs/toolkit'
1+
import { createAction, isActionCreator } from '@reduxjs/toolkit'
22

33
describe('createAction', () => {
44
it('should create an action', () => {
@@ -127,23 +127,6 @@ const actionCreator = createAction('anAction')
127127
class Action {
128128
type = 'totally an action'
129129
}
130-
describe('isAction', () => {
131-
it('should only return true for plain objects with a string type property', () => {
132-
const testCases: [action: unknown, expected: boolean][] = [
133-
[{ type: 'an action' }, true],
134-
[{ type: 'more props', extra: true }, true],
135-
[{ type: 0 }, false],
136-
[actionCreator(), true],
137-
[actionCreator, false],
138-
[Promise.resolve({ type: 'an action' }), false],
139-
[new Action(), false],
140-
['a string', false],
141-
]
142-
for (const [action, expected] of testCases) {
143-
expect(isAction(action)).toBe(expected)
144-
}
145-
})
146-
})
147130

148131
describe('isActionCreator', () => {
149132
it('should only return true for action creators', () => {

packages/toolkit/src/tests/isPlainObject.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)