|
@@ -174,7 +174,7 @@ const store = new Vuex.Store({ ...options })
|
|
|
|
|
|
### subscribe
|
|
### subscribe
|
|
|
|
|
|
-- `subscribe(handler: Function): Function`
|
|
|
|
|
|
+- `subscribe(handler: Function, options?: Object): Function`
|
|
|
|
|
|
Subscribe to store mutations. The `handler` is called after every mutation and receives the mutation descriptor and post-mutation state as arguments:
|
|
Subscribe to store mutations. The `handler` is called after every mutation and receives the mutation descriptor and post-mutation state as arguments:
|
|
|
|
|
|
@@ -185,13 +185,19 @@ const store = new Vuex.Store({ ...options })
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+ 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 overriden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
|
|
|
|
+
|
|
|
|
+ ``` js
|
|
|
|
+ store.subscribe(handler, { prepend: true })
|
|
|
|
+ ```
|
|
|
|
+
|
|
To stop subscribing, call the returned unsubscribe function.
|
|
To stop subscribing, call the returned unsubscribe function.
|
|
|
|
|
|
Most commonly used in plugins. [Details](../guide/plugins.md)
|
|
Most commonly used in plugins. [Details](../guide/plugins.md)
|
|
|
|
|
|
### subscribeAction
|
|
### subscribeAction
|
|
|
|
|
|
-- `subscribeAction(handler: Function): Function`
|
|
|
|
|
|
+- `subscribeAction(handler: Function, options?: Object): Function`
|
|
|
|
|
|
> New in 2.5.0
|
|
> New in 2.5.0
|
|
|
|
|
|
@@ -204,6 +210,12 @@ const store = new Vuex.Store({ ...options })
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+ 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 overriden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
|
|
|
|
+
|
|
|
|
+ ``` js
|
|
|
|
+ store.subscribe(handler, { prepend: true })
|
|
|
|
+ ```
|
|
|
|
+
|
|
To stop subscribing, call the returned unsubscribe function.
|
|
To stop subscribing, call the returned unsubscribe function.
|
|
|
|
|
|
> New in 3.1.0
|
|
> New in 3.1.0
|