You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/action-listener-middleware/README.md
+14-15Lines changed: 14 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# RTK Incubator - Action Listener Middleware
2
2
3
-
This package provides an experimental callback-based Redux middleware that we hope to include in Redux Toolkit directly in a future release. We're publishing it as a standalone package to allow users to try it out separately and give us feedback on its API design.
3
+
This package provides a callback-based Redux middleware that we plan to include in Redux Toolkit directly in a future release. We're publishing it as a standalone package to allow users to try it out separately and give us feedback on its API design.
4
4
5
-
This middleware lets you define callbacks that will run in response to specific actions being dispatched. It's intended to be a lightweight alternative to more widely used Redux async middleware like sagas and observables. While similar to thunks in level of complexity and concept, it can be used to replicate some common saga usage patterns.
5
+
This middleware lets you define "listener" callbacks that will run in response to specific actions being dispatched. It's intended to be a lightweight alternative to more widely used Redux async middleware like sagas and observables. While similar to thunks in level of complexity and concept, it can be used to replicate some common saga usage patterns.
6
6
7
7
## Installation
8
8
@@ -106,7 +106,7 @@ Listeners can be defined statically by calling `listenerMiddleware.addListener()
Creates an instance of the middleware, which should then be added to the store via the`middleware` parameter.
109
+
Creates an instance of the middleware, which should then be added to the store via `configureStore`'s`middleware` parameter.
110
110
111
111
Current options are:
112
112
@@ -166,7 +166,6 @@ middleware.addListener({
166
166
})
167
167
```
168
168
169
-
It throws error if listener is not a function.
170
169
The ["matcher" utility functions included in RTK](https://redux-toolkit.js.org/api/matching-utilities) are acceptable as predicates.
171
170
172
171
The return value is a standard `unsubscribe()` callback that will remove this listener. 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.
@@ -177,7 +176,8 @@ All listener predicates and callbacks are checked _after_ the root reducer has a
Removes a given listener. Accepts the same arguments as `middleware.addListener()` and throws error if listener is not a function.
179
+
Removes a given listener. It accepts the same arguments as `middleware.addListener()`. It checks for an existing listener entry by comparing the function references of `listener` and the provided `actionCreator/matcher/predicate` function or `type` string.
180
+
181
181
Returns `true` if the `options.listener` listener has been removed, `false` if no subscription matching the input provided has been found.
Removes all current listener entries. This is most likely useful for test scenarios where a single middleware or store instance might be used in multiple tests, as well as some app cleanup situations.
197
+
199
198
### `addListenerAction`
200
199
201
-
A standard RTK action creator that tells the middleware to dynamically add a new listener at runtime. It accepts exactly the same options as `middleware.addListener()`
200
+
A standard RTK action creator. Dispatching this action tells the middleware to dynamically add a new listener at runtime. It accepts exactly the same options as `middleware.addListener()`
202
201
203
202
Dispatching this action returns an `unsubscribe()` callback from `dispatch`.
A standard RTK action creator that tells the middleware to remove a listener at runtime. Accepts the same arguments as `middleware.removeListener()`:
213
-
Returns `true` if the `options.listener` listener has been removed, `false` if no subscription matching the input provided has been found.
211
+
A standard RTK action creator. Dispatching this action tells the middleware to dynamically remove a listener at runtime. Accepts the same arguments as `middleware.removeListener()`.
214
212
213
+
Returns `true` if the `options.listener` listener has been removed, `false` if no subscription matching the input provided has been found.
0 commit comments