Skip to content

Commit b1fbb92

Browse files
authored
Merge pull request #1729 from reduxjs/feature/listener-package-fixes
2 parents ecd0757 + c9112c1 commit b1fbb92

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "commonjs" }

packages/action-listener-middleware/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"name": "@rtk-incubator/action-listener-middleware",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"author": {
55
"name": "Lenz Weber",
66
"email": "mail@phryneas.de",
77
"url": "https://phryneas.de/"
88
},
99
"license": "MIT",
1010
"source": "src/index.ts",
11-
"exports": "./dist/index.modern.js",
12-
"main": "./dist/index.cjs",
13-
"module": "./dist/index.module.js",
14-
"unpkg": "./dist/index.umd.js",
11+
"module": "./dist/module/index.js",
12+
"main": "./dist/cjs/index.js",
1513
"types": "./dist/index.d.ts",
1614
"scripts": {
17-
"build": "rimraf dist && microbundle",
15+
"build": "rimraf dist && yarn build:esm && yarn build:module && yarn build:cjs",
16+
"build:esm": "microbundle -o ./dist/esm/index.js -f modern",
17+
"build:module": "microbundle -o ./dist/module/index.js -f esm --generate-types false",
18+
"build:cjs": "microbundle -o ./dist/cjs/index.js -f cjs --generate-types false && cp ./cjs.json ./dist/cjs/package.json",
1819
"dev": "microbundle watch",
1920
"prepublishOnly": "yarn build",
2021
"test": "jest --runInBand"
@@ -38,5 +39,6 @@
3839
"files": [
3940
"src",
4041
"dist"
41-
]
42+
],
43+
"sideEffects": false
4244
}

0 commit comments

Comments
 (0)