Skip to content

Commit efc2de5

Browse files
committed
Remove action creators from middleware instance
1 parent 2c80abb commit efc2de5

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

packages/action-listener-middleware/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
import { createAction, nanoid } from '@reduxjs/toolkit'
1010

1111
import type {
12+
ActionListenerMiddleware,
1213
AddListenerOverloads,
1314
AnyActionListenerPredicate,
1415
CreateListenerMiddlewareOptions,
@@ -461,10 +462,7 @@ export function createActionListenerMiddleware<
461462
{
462463
addListener: addListener as TypedAddListener<S, D>,
463464
removeListener: removeListener as TypedRemoveListener<S, D>,
464-
addListenerAction: addListenerAction as TypedAddListenerAction<S>,
465-
removeListenerAction:
466-
removeListenerAction as TypedRemoveListenerAction<S>,
467-
clear: clearListenerMiddleware,
465+
clearListeners: clearListenerMiddleware,
468466
},
469467
{} as WithMiddlewareType<typeof middleware>
470468
)

packages/action-listener-middleware/src/tests/listenerMiddleware.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import type {
2424
Unsubscribe,
2525
ActionListenerMiddleware,
2626
} from '../index'
27-
import type { ActionListener, AddListenerOverloads } from '../types'
27+
import type {
28+
ActionListener,
29+
AddListenerOverloads,
30+
TypedRemoveListenerAction,
31+
} from '../types'
2832

2933
const middlewareApi = {
3034
getState: expect.any(Function),
@@ -138,6 +142,10 @@ describe('createActionListenerMiddleware', () => {
138142

139143
let reducer: jest.Mock
140144
let middleware: ReturnType<typeof createActionListenerMiddleware>
145+
let addTypedListenerAction =
146+
addListenerAction as TypedAddListenerAction<CounterState>
147+
let removeTypedListenerAction =
148+
removeListenerAction as TypedRemoveListenerAction<CounterState>
141149
// let middleware: ActionListenerMiddleware<CounterState> //: ReturnType<typeof createActionListenerMiddleware>
142150

143151
const testAction1 = createAction<string>('testAction1')
@@ -237,15 +245,15 @@ describe('createActionListenerMiddleware', () => {
237245

238246
expect(
239247
store.dispatch(
240-
middleware.removeListenerAction({
248+
removeTypedListenerAction({
241249
actionCreator: testAction2,
242250
listener,
243251
})
244252
)
245253
).toBe(false)
246254
expect(
247255
store.dispatch(
248-
middleware.removeListenerAction({
256+
removeTypedListenerAction({
249257
actionCreator: testAction1,
250258
listener,
251259
})
@@ -657,7 +665,7 @@ describe('createActionListenerMiddleware', () => {
657665

658666
store.dispatch(testAction1('a'))
659667

660-
middleware.clear()
668+
middleware.clearListeners()
661669
store.dispatch(testAction1('b'))
662670
store.dispatch(testAction2('c'))
663671

@@ -680,7 +688,7 @@ describe('createActionListenerMiddleware', () => {
680688

681689
store.dispatch(testAction1('a'))
682690

683-
middleware.clear()
691+
middleware.clearListeners()
684692
store.dispatch(testAction1('b'))
685693

686694
expect(await fork1Test).toHaveProperty('status', 'cancelled')
@@ -1385,7 +1393,7 @@ describe('createActionListenerMiddleware', () => {
13851393
})
13861394

13871395
store.dispatch(
1388-
typedMiddleware.addListenerAction({
1396+
addTypedListenerAction({
13891397
predicate: (
13901398
action,
13911399
currentState,
@@ -1409,7 +1417,7 @@ describe('createActionListenerMiddleware', () => {
14091417
)
14101418

14111419
store.dispatch(
1412-
typedMiddleware.addListenerAction({
1420+
addTypedListenerAction({
14131421
predicate: (
14141422
action,
14151423
currentState,

packages/action-listener-middleware/src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ export type ActionListenerMiddleware<
217217
> & {
218218
addListener: AddListenerOverloads<Unsubscribe, S, D>
219219
removeListener: RemoveListenerOverloads<S, D>
220-
addListenerAction: TypedAddListenerAction<S, D>
221-
removeListenerAction: TypedRemoveListenerAction<S, D>
222220
/**
223221
* Unsubscribes all listeners, cancels running listeners and tasks.
224222
*/
225-
clear: () => void
223+
clearListeners: () => void
226224
}
227225

228226
/**

0 commit comments

Comments
 (0)