Skip to content

Commit

Permalink
Fixed option merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Feb 20, 2017
1 parent 9299f98 commit e1f6c14
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Vue.use(VueMeteorTracker);

*Note: if you are using the Meteor [akryum:vue](https://github.com/Akryum/meteor-vue-component/tree/master/packages/vue) package, you don't need to install the plugin.*

**⚠️ You may need to polyfill `Object.assign`.**

## Usage

In your Vue component, add a `meteor` object :
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-meteor-tracker",
"version": "1.0.4",
"version": "1.1.1",
"description": "Use Meteor Tracker reactivity inside Vue components",
"main": "index.js",
"scripts": {
Expand Down
21 changes: 20 additions & 1 deletion src/vue-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function defaultSubscription(...args) {

export default {
install(Vue, options) {

const vueVersion = parseInt(Vue.version.charAt(0));

const { defineReactive } = Vue.util;
Expand All @@ -21,6 +21,25 @@ export default {
for(const k in options) {
Vue.config.meteor[k] = options[k];
}

const merge = Vue.config.optionMergeStrategies.methods
Vue.config.optionMergeStrategies.meteor = function (toVal, fromVal, vm) {
if (!toVal) return fromVal
if (!fromVal) return toVal

const toData = Object.assign({}, omit(toVal, [
'subscribe',
'data',
]), toVal.data);
const fromData = Object.assign({}, omit(fromVal, [
'subscribe',
'data',
]), fromVal.data);

return Object.assign({
subscribe: merge(toVal.subscribe, fromVal.subscribe),
}, merge(toData, fromData))
}

function prepare() {
this._trackerHandles = [];
Expand Down

0 comments on commit e1f6c14

Please sign in to comment.