Ver código fonte

update docs for 1.0-rc.2

Evan You 8 anos atrás
pai
commit
234a3bf7cb
2 arquivos alterados com 11 adições e 10 exclusões
  1. 8 7
      docs/en/api.md
  2. 3 3
      docs/en/plugins.md

+ 8 - 7
docs/en/api.md

@@ -102,12 +102,13 @@ const store = new Vuex.Store({ ...options })
 
   Hot swap new actions and mutations. [Details](hot-reload.md)
 
-- **on(event: String, cb: Function)**
+- **subscribe(handler: Function)**
 
-- **once(event: String, cb: Function)**
+  Subscribe to store mutations. The `handler` is called after every mutaiton and receives the mutation descriptor and post-mutation state as arguments:
 
-- **off([event: String, cb: Function])**
-
-- **emit(event: String, ...args)**
-
-  Same event interface as found on a Vue instance. The only event the store emits is `mutation` (see [Plugins](plugins.md)).
+  ``` js
+  store.subscribe((mutation, state) => {
+    console.log(mutation.type)
+    console.log(mutation.payload)
+  })
+  ```

+ 3 - 3
docs/en/plugins.md

@@ -5,7 +5,7 @@ Vuex stores accept the `plugins` option that exposes hooks for each mutation. A
 ``` js
 const myPlugin = store => {
   // called when the store is initialized
-  store.on('mutation', (mutation, state) => {
+  store.subscribe((mutation, state) => {
     // called after every mutation.
     // The mutation comes in the format of { type, payload } for normal
     // dispatches, and will be the original mutation object for object-style
@@ -35,7 +35,7 @@ export default function createWebSocketPlugin (socket) {
     socket.on('data', data => {
       store.dispatch('RECEIVE_DATA', data)
     })
-    store.on('mutation', (mutation) => {
+    store.subscribe(mutation => {
       if (mutation.type === 'UPDATE_DATA') {
         socket.emit('update', mutation.payload)
       }
@@ -61,7 +61,7 @@ Sometimes a plugin may want to receive "snapshots" of the state, and also compar
 ``` js
 const myPluginWithSnapshot = store => {
   let prevState = _.cloneDeep(store.state)
-  store.on('mutation', (mutation, state) => {
+  store.subscribe((mutation, state) => {
     let nextState = _.cloneDeep(state)
 
     // compare prevState and nextState...