Skip to content

Commit 3463225

Browse files
authored
Merge pull request #3904 from reduxjs/redux5-rc1
2 parents 6778062 + eeca80a commit 3463225

File tree

13 files changed

+24
-119
lines changed

13 files changed

+24
-119
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
@@ -112,7 +112,7 @@
112112
],
113113
"dependencies": {
114114
"immer": "^10.0.3",
115-
"redux": "^5.0.0-rc.0",
115+
"redux": "^5.0.0-rc.1",
116116
"redux-thunk": "^3.0.0-rc.0",
117117
"reselect": "^5.0.0-beta.1"
118118
},

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: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { Action, UnknownAction } 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
@@ -84,7 +83,7 @@ export type _ActionCreatorWithPreparedPayload<
8483
*/
8584
export interface BaseActionCreator<P, T extends string, M = never, E = never> {
8685
type: T
87-
match: (action: Action<string>) => action is PayloadAction<P, T, M, E>
86+
match: (action: unknown) => action is PayloadAction<P, T, M, E>
8887
}
8988

9089
/**
@@ -279,23 +278,12 @@ export function createAction(type: string, prepareAction?: Function): any {
279278

280279
actionCreator.type = type
281280

282-
actionCreator.match = (action: Action<string>): action is PayloadAction =>
283-
action.type === type
281+
actionCreator.match = (action: unknown): action is PayloadAction =>
282+
isAction(action) && action.type === type
284283

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/dynamicMiddleware/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
UnknownAction,
55
} from 'redux'
66
import { compose } from 'redux'
7-
import { createAction, isAction } from '../createAction'
7+
import { createAction } from '../createAction'
88
import { isAllOf } from '../matchers'
99
import { nanoid } from '../nanoid'
1010
import { emplace, find } from '../utils'
@@ -75,11 +75,7 @@ export const createDynamicMiddleware = <
7575
return compose(...appliedMiddleware)
7676
}
7777

78-
const isWithMiddleware = isAllOf(
79-
isAction,
80-
withMiddleware,
81-
matchInstance(instanceId)
82-
)
78+
const isWithMiddleware = isAllOf(withMiddleware, matchInstance(instanceId))
8379

8480
const middleware: DynamicMiddleware<State, Dispatch> =
8581
(api) => (next) => (action) => {

packages/toolkit/src/dynamicMiddleware/tests/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Middleware } from 'redux'
22
import { createDynamicMiddleware } from '../index'
33
import { configureStore } from '../../configureStore'
44
import type { BaseActionCreator, PayloadAction } from '../../createAction'
5-
import { isAction } from '../../createAction'
65
import { createAction } from '../../createAction'
76
import { isAllOf } from '../../matchers'
87

@@ -25,7 +24,7 @@ export const makeProbeableMiddleware = <Id extends number>(
2524
): Middleware<{
2625
(action: PayloadAction<Id, typeof probeType>): Id
2726
}> => {
28-
const isMiddlewareAction = isAllOf(isAction, probeMiddleware, matchId(id))
27+
const isMiddlewareAction = isAllOf(probeMiddleware, matchId(id))
2928
return (api) => (next) => (action) => {
3029
if (isMiddlewareAction(action)) {
3130
return id

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

0 commit comments

Comments
 (0)