Ver Fonte

[docs] Add helpers reference and update mapState description (#356)

* add helpers reference

* add mapState description
katashin há 8 anos atrás
pai
commit
2b16a119aa
2 ficheiros alterados com 30 adições e 0 exclusões
  1. 18 0
      docs/en/api.md
  2. 12 0
      docs/en/state.md

+ 18 - 0
docs/en/api.md

@@ -157,3 +157,21 @@ const store = new Vuex.Store({ ...options })
 - **`hotUpdate(newOptions: Object)`**
 
   Hot swap new actions and mutations. [Details](hot-reload.md)
+
+### Component Binding Helpers
+
+- **`mapState(map: Array<string> | Object): Object`**
+
+  Create component computed options that return the sub tree of the Vuex store. [Defails](state.md#the-mapstate-helper)
+
+- **`mapGetters(map: Array<string> | Object): Object`**
+
+  Create component computed options that return the evaluated value of a getter. [Details](getters.md#the-mapgetters-helper)
+
+- **`mapActions(map: Array<string> | Object): Object`**
+
+  Create component methods options that dispatch an action. [Details](actions.md#dispatching-actions-in-components)
+
+- **`mapMutations(map: Array<string> | Object): Object`**
+
+  Create component methods options that commit a mutation. [Details](mutations.md#commiting-mutations-in-components)

+ 12 - 0
docs/en/state.md

@@ -70,6 +70,9 @@ export default {
     // arrow functions can make the code very succinct!
     count: state => state.count,
 
+    // passing the string value 'count' is same as `state => state.count`
+    countAlias: 'count',
+
     // to access local state with `this`, a normal function must be used
     countPlusLocalState (state) {
       return state.count + this.localCount
@@ -78,6 +81,15 @@ export default {
 }
 ```
 
+We can also pass a string array to `mapState` when the name of mapped computed property is same as state sub tree name.
+
+``` js
+computed: mapState([
+  // map this.count to store.state.count
+  'count'
+])
+```
+
 ### Object Spread Operator
 
 Note that `mapState` returns an object. How do we use it in combination with other local computed properties? Normally, we'd have to use a utility to merge multiple objects into one so that we can pass the final object to `computed`. However with the [object spread operator](https://github.com/sebmarkbage/ecmascript-rest-spread) (which is a stage-3 ECMASCript proposal), we can greatly simplify the syntax: