Skip to content

Commit c627e92

Browse files
committed
Clarify docs wording
1 parent a3be5b2 commit c627e92

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/action-listener-middleware/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ For more background and debate over the use cases and API design, see the origin
8888

8989
## API Reference
9090

91-
`createActionListenerMiddleware` lets you add listeners by providing an action type and a callback, lets you specify whether your callback should run before or after the action is processed by the reducers, and gives you access to `dispatch` and `getState` for use in your logic. Callbacks can also unsubscribe.
91+
`createActionListenerMiddleware` lets you add listeners by providing a "listener callback" containing additional logic, a way to specify when that callback should run based on dispatched actions or state changes, and whether your callback should run before or after the action is processed by the reducers.
92+
93+
The middleware then gives you access to `dispatch` and `getState` for use in your listener callback's logic. Callbacks can also unsubscribe to stop from being run again in the future.
9294

9395
Listeners can be defined statically by calling `listenerMiddleware.addListener()` during setup, or added and removed dynamically at runtime with special `dispatch(addListenerAction())` and `dispatch(removeListenerAction())` actions.
9496

@@ -119,7 +121,9 @@ Parameters:
119121
- `unsubscribe` will remove the listener from the middleware
120122
- `options: {when?: 'before' | 'after'}`: an options object. Currently only one options field is accepted - an enum indicating whether to run this listener 'before' the action is processed by the reducers, or 'after'. If not provided, the default is 'after'.
121123

122-
The return value is a standard `unsubscribe()` callback that will remove this listener. If a listener entry with this exact function reference already exists, no new entry will be added, and the existing `unsubscribe` method will be returned.
124+
The return value is a standard `unsubscribe()` callback that will remove this listener.
125+
126+
If you try to add a listener entry but another entry with this exact function reference already exists, no new entry will be added, and the existing `unsubscribe` method will be returned.
123127

124128
Adding a listener takes a "listener predicate" callback, which will be called when an action is dispatched, and should return `true` if the listener itself should be called:
125129

0 commit comments

Comments
 (0)