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
Setting this makes your [action](/docs/api/action)*listen* to provided *target*[action](/docs/api/action), [thunk](/docs/api/thunk), or string named action. Any time the *target* is successfully processed then this [action](/docs/api/action) will be fired.
32
+
Setting this makes your [action](/docs/api/action)*listen* to provided *target(s)*[action(s)](/docs/api/action), [thunk(s)](/docs/api/thunk), or string named action(s). Any time the *target(s)* is successfully processed then this [action](/docs/api/action) will be fired.
33
33
34
-
The *listener* will receive the same payload as was supplied to the *target*.
34
+
The *listener* will receive the same payload as was supplied to the *target(s)*.
35
35
36
36
```javascript
37
37
constauditModel= {
@@ -100,6 +100,40 @@ In the example above note that the `onAddTodo` [action](/docs/api/action) has be
100
100
101
101
Any time the `addTodo` [action](/docs/api/action) completes successfully, the `onAddTodo` will be fired, receiving the same payload as what `addTodo` received.
102
102
103
+
## Listening to multiple actions
104
+
105
+
It is possible for a *listening* action to listen to multiple *targets*. Simply provide an array of*targets* against the `listenTo` configuration.
106
+
107
+
```javascript
108
+
const fooModel = {
109
+
items: [],
110
+
// 👇 the first target action
111
+
firstAction: action((state, payload) => {
112
+
state.items.push(payload);
113
+
}),
114
+
// 👇 the second target action
115
+
secondAction action((state, payload) => {
116
+
state.items.push(payload);
117
+
}),
118
+
};
119
+
120
+
const auditModel = {
121
+
logs: [],
122
+
onAddTodo: action(
123
+
(state, payload) => {
124
+
state.logs.push(payload);
125
+
},
126
+
{
127
+
// 👇 declare the targets within an array
128
+
listenTo: [
129
+
fooModel.firstAction,
130
+
fooModel.secondAction
131
+
]
132
+
}
133
+
)
134
+
};
135
+
```
136
+
103
137
## Using console.log within actions
104
138
105
139
Despite the Redux Dev Tools extension being available there may be cases in which you would like to perform a `console.log` within the body of your [actions](/docs/api/action) to aid debugging.
0 commit comments