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

Add Support for loading fromMobx attributes from mixins on components. #21

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})