Skip to content

Commit

Permalink
Add vuex merging strategy as an example in mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 26, 2016
1 parent e668d2d commit edfa1f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/guide/mixins.md
Expand Up @@ -125,3 +125,18 @@ For most object-based options, you can simply use the same strategy used by `met
var strategies = Vue.config.optionMergeStrategies
strategies.myOption = strategies.methods
```

A more advanced example can be found on [Vuex](https://github.com/vuejs/vuex)'s merging strategy:

``` js
const merge = Vue.config.optionMergeStrategies.computed
Vue.config.optionMergeStrategies.vuex = (toVal, fromVal) => {
if (!toVal) return fromVal
if (!fromVal) return toVal
return {
getters: merge(toVal.getters, fromVal.getters),
state: merge(toVal.state, fromVal.state),
actions: merge(toVal.actions, fromVal.actions)
}
}
```

2 comments on commit edfa1f9

@kazupon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be used ES5 features.
See the guideline :)
#319

@posva
Copy link
Member Author

@posva posva commented on edfa1f9 Jun 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixing it

Please sign in to comment.