|
@@ -7,7 +7,7 @@ const myPlugin = store => {
|
|
// called when the store is initialized
|
|
// called when the store is initialized
|
|
store.subscribe((mutation, state) => {
|
|
store.subscribe((mutation, state) => {
|
|
// called after every mutation.
|
|
// called after every mutation.
|
|
- // The mutation comes in the format of { type, payload }.
|
|
|
|
|
|
+ // The mutation comes in the format of `{ type, payload }`.
|
|
})
|
|
})
|
|
}
|
|
}
|
|
```
|
|
```
|
|
@@ -62,7 +62,7 @@ const myPluginWithSnapshot = store => {
|
|
store.subscribe((mutation, state) => {
|
|
store.subscribe((mutation, state) => {
|
|
let nextState = _.cloneDeep(state)
|
|
let nextState = _.cloneDeep(state)
|
|
|
|
|
|
- // compare prevState and nextState...
|
|
|
|
|
|
+ // compare `prevState` and `nextState`...
|
|
|
|
|
|
// save state for next mutation
|
|
// save state for next mutation
|
|
prevState = nextState
|
|
prevState = nextState
|
|
@@ -70,7 +70,7 @@ const myPluginWithSnapshot = store => {
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
-**Plugins that take state snapshots should be used only during development.** When using Webpack or Browserify, we can let our build tools handle that for us:
|
|
|
|
|
|
+**Plugins that take state snapshots should be used only during development.** When using webpack or Browserify, we can let our build tools handle that for us:
|
|
|
|
|
|
``` js
|
|
``` js
|
|
const store = new Vuex.Store({
|
|
const store = new Vuex.Store({
|
|
@@ -81,7 +81,7 @@ const store = new Vuex.Store({
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
-The plugin will be used by default. For production, you will need [DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin) for Webpack or [envify](https://github.com/hughsk/envify) for Browserify to convert the value of `process.env.NODE_ENV !== 'production'` to `false` for the final build.
|
|
|
|
|
|
+The plugin will be used by default. For production, you will need [DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin) for webpack or [envify](https://github.com/hughsk/envify) for Browserify to convert the value of `process.env.NODE_ENV !== 'production'` to `false` for the final build.
|
|
|
|
|
|
### Built-in Logger Plugin
|
|
### Built-in Logger Plugin
|
|
|
|
|
|
@@ -103,8 +103,8 @@ The `createLogger` function takes a few options:
|
|
const logger = createLogger({
|
|
const logger = createLogger({
|
|
collapsed: false, // auto-expand logged mutations
|
|
collapsed: false, // auto-expand logged mutations
|
|
filter (mutation, stateBefore, stateAfter) {
|
|
filter (mutation, stateBefore, stateAfter) {
|
|
- // returns true if a mutation should be logged
|
|
|
|
- // `mutation` is a { type, payload }
|
|
|
|
|
|
+ // returns `true` if a mutation should be logged
|
|
|
|
+ // `mutation` is a `{ type, payload }`
|
|
return mutation.type !== "aBlacklistedMutation"
|
|
return mutation.type !== "aBlacklistedMutation"
|
|
},
|
|
},
|
|
transformer (state) {
|
|
transformer (state) {
|
|
@@ -113,7 +113,7 @@ const logger = createLogger({
|
|
return state.subTree
|
|
return state.subTree
|
|
},
|
|
},
|
|
mutationTransformer (mutation) {
|
|
mutationTransformer (mutation) {
|
|
- // mutations are logged in the format of { type, payload }
|
|
|
|
|
|
+ // mutations are logged in the format of `{ type, payload }`
|
|
// we can format it any way we want.
|
|
// we can format it any way we want.
|
|
return mutation.type
|
|
return mutation.type
|
|
}
|
|
}
|