@@ -5,7 +5,7 @@ Vuex stores accept the `plugins` option that exposes hooks for each mutation. A
55``` js
66const myPlugin = store => {
77 // called when the store is initialized
8- store .on ( ' mutation ' , (mutation , state ) => {
8+ store .subscribe ( (mutation , state ) => {
99 // called after every mutation.
1010 // The mutation comes in the format of { type, payload } for normal
1111 // dispatches, and will be the original mutation object for object-style
@@ -35,7 +35,7 @@ export default function createWebSocketPlugin (socket) {
3535 socket .on (' data' , data => {
3636 store .dispatch (' RECEIVE_DATA' , data)
3737 })
38- store .on ( ' mutation' , ( mutation ) => {
38+ store .subscribe ( mutation => {
3939 if (mutation .type === ' UPDATE_DATA' ) {
4040 socket .emit (' update' , mutation .payload )
4141 }
@@ -61,7 +61,7 @@ Sometimes a plugin may want to receive "snapshots" of the state, and also compar
6161``` js
6262const myPluginWithSnapshot = store => {
6363 let prevState = _ .cloneDeep (store .state )
64- store .on ( ' mutation ' , (mutation , state ) => {
64+ store .subscribe ( (mutation , state ) => {
6565 let nextState = _ .cloneDeep (state)
6666
6767 // compare prevState and nextState...
0 commit comments