From a8334e44dae2cd31951f77a229ca9bf697a9737b Mon Sep 17 00:00:00 2001 From: Tyler Petresky Date: Wed, 14 Mar 2018 15:22:23 -0400 Subject: [PATCH] Add support for loading frmoMobx attributes from mixins on components. --- src/install.ts | 9 ++++++++- test/index.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/install.ts b/src/install.ts index 90d6bd3..a76c368 100644 --- a/src/install.ts +++ b/src/install.ts @@ -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 [] } diff --git a/test/index.ts b/test/index.ts index edb2d06..50125b4 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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() +})