From c74da4a72397937d1dae70c0955f6d6a59cb1aee Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Wed, 6 Dec 2017 14:51:22 +0100 Subject: [PATCH 1/3] Call hook with vm arg when data merging --- src/core/util/options.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/util/options.js b/src/core/util/options.js index ad36bb94151..945d43c69b8 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -85,18 +85,18 @@ export function mergeDataOrFn ( // it has to be a function to pass previous merges. return function mergedDataFn () { return mergeData( - typeof childVal === 'function' ? childVal.call(this) : childVal, - typeof parentVal === 'function' ? parentVal.call(this) : parentVal + typeof childVal === 'function' ? childVal.call(this, this) : childVal, + typeof parentVal === 'function' ? parentVal.call(this, this) : parentVal ) } } else { return function mergedInstanceDataFn () { // instance merge const instanceData = typeof childVal === 'function' - ? childVal.call(vm) + ? childVal.call(vm, vm) : childVal const defaultData = typeof parentVal === 'function' - ? parentVal.call(vm) + ? parentVal.call(vm, vm) : parentVal if (instanceData) { return mergeData(instanceData, defaultData) From 499475004e1a18a4bd188e70b45ef0877a02f6c2 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Wed, 6 Dec 2017 14:51:38 +0100 Subject: [PATCH 2/3] Unit test --- test/unit/features/options/data.spec.js | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/unit/features/options/data.spec.js b/test/unit/features/options/data.spec.js index 29a48c38b44..11a37b1e7f6 100644 --- a/test/unit/features/options/data.spec.js +++ b/test/unit/features/options/data.spec.js @@ -123,4 +123,32 @@ describe('Options data', () => { }).$mount() expect(vm.$el.innerHTML).toBe('foo:1') }) + + it('should called with this when merged', () => { + const superComponent = { + data: ({ foo }) => ({ ext: 'ext:' + foo }) + } + const mixins = [ + { + data: ({ foo }) => ({ mixin1: 'm1:' + foo }) + }, + { + data: ({ foo }) => ({ mixin2: 'm2:' + foo }) + } + ] + const vm = new Vue({ + template: '
', + provide: { foo: 1 }, + components: { + child: { + extends: superComponent, + mixins, + template: '{{bar}}-{{ext}}-{{mixin1}}-{{mixin2}}', + inject: ['foo'], + data: ({ foo }) => ({ bar: 'foo:' + foo }) + } + } + }).$mount() + expect(vm.$el.innerHTML).toBe('foo:1-ext:1-m1:1-m2:1') + }) }) From 6d58963f662f9e320859ca04125c09bdffb205de Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 6 Dec 2017 09:11:20 -0500 Subject: [PATCH 3/3] Update data.spec.js --- test/unit/features/options/data.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/features/options/data.spec.js b/test/unit/features/options/data.spec.js index 11a37b1e7f6..cb8a75ad18d 100644 --- a/test/unit/features/options/data.spec.js +++ b/test/unit/features/options/data.spec.js @@ -107,7 +107,7 @@ describe('Options data', () => { expect(vm.a).toBe(1) }) - it('should called with this', () => { + it('should be called with this', () => { const vm = new Vue({ template: '
', provide: { foo: 1 }, @@ -124,7 +124,7 @@ describe('Options data', () => { expect(vm.$el.innerHTML).toBe('foo:1') }) - it('should called with this when merged', () => { + it('should be called with vm as first argument when merged', () => { const superComponent = { data: ({ foo }) => ({ ext: 'ext:' + foo }) }