Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from Tresky/add-mixin-support
Browse files Browse the repository at this point in the history
Add Support for loading fromMobx attributes from mixins on components.
  • Loading branch information
nighca committed Mar 16, 2018
2 parents eea3787 + a8334e4 commit a6bdc84
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ function createComputedProperty(
}

function getFromStoreEntries(vm: VueClass): FromMobxEntry[] {
const fromStore = vm.$options.fromMobx
let fromStore = vm.$options.fromMobx
if (vm.$options.mixins) {
var fromStoreNew = vm.$options.mixins
.map(mixin => mixin.fromMobx)
.reduce((accum, mobx) => mobx ? Object.assign({}, accum, mobx) : accum, {})
fromStore = Object.assign({}, fromStore, fromStoreNew)
}

if (!fromStore) {
return []
}
Expand Down
33 changes: 33 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,36 @@ test('normal components destroy well', () => {

vm.$destroy()
})

test('fromMobx attributes pulled from mixins', () => {
Vue.use(Movue)

const data = observable({
foo: 1
})

const mixin = {
fromMobx: {
foo () {
return data.foo
}
}
}

const vm = new Vue({
mixins: [mixin],
computed: {
value () {
return this.foo
}
},
render (h) {
const vm: any = this
return h('div', `${vm.value}`)
}
}).$mount()

expect(vm.foo).toBe(1)

vm.$destroy()
})

0 comments on commit a6bdc84

Please sign in to comment.