Skip to content

Commit 147a1eb

Browse files
Fix comparison with proxy value (#640)
* Fix comparison with proxy value * Fix lint
1 parent d9c3fd5 commit 147a1eb

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

packages/devextreme-vue/src/core/__tests__/configuration.test.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Configuration, {
55
UpdateFunc
66
} from "../configuration";
77

8-
import { ComponentPublicInstance } from "vue";
8+
import { ComponentPublicInstance, reactive } from "vue";
99

1010
function createRootConfig(updateFunc: UpdateFunc): Configuration {
1111
return new Configuration(updateFunc, null, {});
@@ -177,6 +177,33 @@ it("binds option watchers", () => {
177177
expect(updateValueFunc.mock.calls[0][1]).toBe(value);
178178
});
179179

180+
it("should update only when raw value not equal", () => {
181+
const updateValueFunc = jest.fn();
182+
const $watchFunc = jest.fn();
183+
const innerChanges = { prop1: "test" };
184+
185+
bindOptionWatchers(
186+
{
187+
updateValue: updateValueFunc,
188+
getOptionsToWatch: () => ["prop1"],
189+
innerChanges: {}
190+
} as any,
191+
{
192+
$watch: $watchFunc
193+
},
194+
innerChanges
195+
);
196+
197+
$watchFunc.mock.calls[0][1](reactive(innerChanges).prop1);
198+
199+
expect(updateValueFunc).toHaveBeenCalledTimes(0);
200+
201+
$watchFunc.mock.calls[0][1](reactive({ prop1: "test1"}).prop1);
202+
expect(updateValueFunc).toHaveBeenCalledTimes(1);
203+
expect(updateValueFunc.mock.calls[0][0]).toBe("prop1");
204+
expect(updateValueFunc.mock.calls[0][1]).toBe("test1");
205+
});
206+
180207
describe("initial configuration", () => {
181208

182209
it("pulls value from nested", () => {

packages/devextreme-vue/src/core/configuration.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentPublicInstance as IVue, VNode, VNodeProps } from "vue";
1+
import { ComponentPublicInstance as IVue, toRaw, VNode, VNodeProps } from "vue";
22
import { getOption } from "./config";
33
import { IComponentInfo } from "./configuration-component";
44
import { getOptionInfo, isEqual } from "./helpers";
@@ -264,8 +264,9 @@ function bindOptionWatchers(
264264
if (targets) {
265265
targets.forEach((optionName: string) => {
266266
vueInstance.$watch(optionName, (value) => {
267+
const rawValue = toRaw(value);
267268
if (!innerChanges.hasOwnProperty(optionName) ||
268-
innerChanges[optionName] !== value) {
269+
innerChanges[optionName] !== rawValue) {
269270
config.updateValue(optionName, value);
270271
}
271272
delete innerChanges[optionName];
@@ -293,7 +294,7 @@ function setEmitOptionChangedFunc(
293294
const props = vueInstance.$props;
294295
const vnode = vueInstance?.$?.vnode;
295296
if (hasProp(vueInstance, name) && !isEqual(value, props[name]) && vueInstance.$emit) {
296-
innerChanges[name] = value;
297+
innerChanges[name] = toRaw(value);
297298
const eventName = name === "value" && hasVModelValue(vueInstance.$options, props, vnode) ?
298299
`update:${VMODEL_NAME}` :
299300
`update:${name}`;

0 commit comments

Comments
 (0)