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
// You may call unsubscribe to stop the subscription
188
+
unsubscribe()
186
189
```
187
190
188
191
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overridden by adding `prepend:true` to `options`, which will add the handler to the beginning of the chain.
@@ -191,7 +194,7 @@ const store = new Vuex.Store({ ...options })
191
194
store.subscribe(handler, { prepend:true })
192
195
```
193
196
194
-
To stop subscribing, call the returned unsubscribe function.
197
+
The `subscribe` method will return an `unsubscribe` function, which should be called when the subscription is no longer needed. For example, you might subscribe to a Vuex Module and unsubscribe when you unregister the module. Or you might call `subscribe` from inside a Vue Component and then destroy the component later. In these cases, you should remember to unsubscribe the subscription manually.
195
198
196
199
Most commonly used in plugins. [Details](../guide/plugins.md)
197
200
@@ -201,13 +204,17 @@ const store = new Vuex.Store({ ...options })
201
204
202
205
> New in 2.5.0
203
206
204
-
Subscribe to store actions. The `handler` is called for every dispatched action and receives the action descriptor and current store state as arguments:
207
+
Subscribe to store actions. The `handler` is called for every dispatched action and receives the action descriptor and current store state as arguments.
208
+
The `subscribe` method will return an `unsubscribe` function, which should be called when the subscription is no longer needed. For example, when unregistering a Vuex module or before destroying a Vue component.
// You may call unsubscribe to stop the subscription
217
+
unsubscribe()
211
218
```
212
219
213
220
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overridden by adding `prepend:true` to `options`, which will add the handler to the beginning of the chain.
@@ -216,7 +223,7 @@ const store = new Vuex.Store({ ...options })
216
223
store.subscribeAction(handler, { prepend:true })
217
224
```
218
225
219
-
To stop subscribing, call the returned unsubscribe function.
226
+
The `subscribeAction` method will return an `unsubscribe` function, which should be called when the subscription is no longer needed. For example, you might subscribe to a Vuex Module and unsubscribe when you unregister the module. Or you might call `subscribeAction` from inside a Vue Component and then destroy the component later. In these cases, you should remember to unsubscribe the subscription manually.
0 commit comments