From aead1660ea7f54b45c4f0193270d4fa3bc62b930 Mon Sep 17 00:00:00 2001 From: ygj6 Date: Tue, 11 May 2021 15:29:26 +0800 Subject: [PATCH 1/3] fix: The behavior of dev and production merge should be consistent. --- src/utils/instance.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/instance.ts b/src/utils/instance.ts index 3ee24edc..95168791 100644 --- a/src/utils/instance.ts +++ b/src/utils/instance.ts @@ -36,7 +36,12 @@ export function asVmProperty( }, }) } else { - vm._data[propName] = propValue + proxy(vm._data, propName, { + get: () => propValue, + set: (val: any) => { + propValue = val + }, + }) } }) } From 055d14d8966e90f771f36c9dbe0606180a972de1 Mon Sep 17 00:00:00 2001 From: ygj6 Date: Tue, 11 May 2021 16:38:57 +0800 Subject: [PATCH 2/3] test: add test cases. --- test/setup.spec.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/setup.spec.js b/test/setup.spec.js index 35329849..db4fc0ae 100644 --- a/test/setup.spec.js +++ b/test/setup.spec.js @@ -896,6 +896,94 @@ describe('setup', () => { expect(vm.$el.textContent).toBe('2') }) + //#679 + it('should work merge with object in development', async () => { + global.__DEV__ = true + const vm = new Vue({ + template: '
{{ data.id }}
', + setup() { + const data = reactive({ + id: 42, + }); + return { data } + }, + data() { + return { + data: { id: 1 }, + } + }, + }).$mount() + + await nextTick() + expect(vm.$el.textContent).toBe('1') + }) + + //#679 + it('should work merge with object in production', async () => { + global.__DEV__ = false + const vm = new Vue({ + template: '
{{ data.id }}
', + setup() { + const data = reactive({ + id: 42, + }); + return { data } + }, + data() { + return { + data: { id: 1 }, + } + }, + }).$mount() + + await nextTick() + expect(vm.$el.textContent).toBe('1') + }) + + //#679 + it('should work merge with data in development', async () => { + global.__DEV__ = true + const vm = new Vue({ + template: '
{{ id }}
', + setup() { + const data = reactive({ + id: 42, + }); + return data + }, + data() { + return { + id: 1, + } + }, + }).$mount() + + await nextTick() + expect(vm.$el.textContent).toBe('1') + }) + + //#679 + it('should work merge with data in production', async () => { + global.__DEV__ = false + const vm = new Vue({ + template: '
{{ id }}
', + setup() { + const data = reactive({ + id: 42, + }); + return data + }, + data() { + return { + id: 1, + } + }, + }).$mount() + + await nextTick() + expect(vm.$el.textContent).toBe('1') + }) + // #524 it('should work with reactive arrays.', async () => { const opts = { From 0400f9193518f6ef69b1590a46b9f9ced0bfdb7d Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 19 May 2021 17:33:22 +0800 Subject: [PATCH 3/3] chore: fix conflict --- test/setup.spec.js | 50 ++++------------------------------------------ 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/test/setup.spec.js b/test/setup.spec.js index 0e9a65e1..e1ac9a6d 100644 --- a/test/setup.spec.js +++ b/test/setup.spec.js @@ -898,7 +898,7 @@ describe('setup', () => { expect(vm.$el.textContent).toBe('2') }) - //#679 + // #679 it('should work merge with object in development', async () => { global.__DEV__ = true const vm = new Vue({ @@ -906,7 +906,7 @@ describe('setup', () => { setup() { const data = reactive({ id: 42, - }); + }) return { data } }, data() { @@ -920,7 +920,7 @@ describe('setup', () => { expect(vm.$el.textContent).toBe('1') }) - //#679 + // #679 it('should work merge with object in production', async () => { global.__DEV__ = false const vm = new Vue({ @@ -928,7 +928,7 @@ describe('setup', () => { setup() { const data = reactive({ id: 42, - }); + }) return { data } }, data() { @@ -942,48 +942,6 @@ describe('setup', () => { expect(vm.$el.textContent).toBe('1') }) - //#679 - it('should work merge with data in development', async () => { - global.__DEV__ = true - const vm = new Vue({ - template: '
{{ id }}
', - setup() { - const data = reactive({ - id: 42, - }); - return data - }, - data() { - return { - id: 1, - } - }, - }).$mount() - - await nextTick() - expect(vm.$el.textContent).toBe('1') - }) - - //#679 - it('should work merge with data in production', async () => { - global.__DEV__ = false - const vm = new Vue({ - template: '
{{ id }}
', - setup() { - const data = reactive({ - id: 42, - }); - return data - }, - data() { - return { - id: 1, - } - }, - }).$mount() - - await nextTick() - expect(vm.$el.textContent).toBe('1') // #683 #603 #580 it('should update directly when adding attributes to a reactive object', async () => { const vm = new Vue({