Skip to content

Commit 37c51e7

Browse files
committed
Ensure listeners added via action are handled the same as others
1 parent dca6ab1 commit 37c51e7

File tree

1 file changed

+9
-1
lines changed
  • packages/action-listener-middleware/src

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,15 @@ export function createActionListenerMiddleware<
421421
D
422422
> = (api) => (next) => (action) => {
423423
if (addListenerAction.match(action)) {
424-
return insertEntry(action.payload)
424+
let entry = findListenerEntry(
425+
(existingEntry) => existingEntry.listener === action.payload.listener
426+
)
427+
428+
if (!entry) {
429+
entry = action.payload
430+
}
431+
432+
return insertEntry(entry)
425433
}
426434
if (removeListenerAction.match(action)) {
427435
removeListener(action.payload.type, action.payload.listener)

0 commit comments

Comments
 (0)