Skip to content

Commit 7e60d10

Browse files
committed
perf: use sync watcher for defineModel local mode
ref vuejs/rfcs#503 (comment)
1 parent 70eca21 commit 7e60d10

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/runtime-core/src/apiSetupHelpers.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { warn } from './warning'
3232
import { SlotsType, StrictUnwrapSlotsType } from './componentSlots'
3333
import { Ref, ref } from '@vue/reactivity'
34-
import { watch } from './apiWatch'
34+
import { watch, watchSyncEffect } from './apiWatch'
3535

3636
// dev only
3737
const warnRuntimeUsage = (method: string) =>
@@ -378,18 +378,20 @@ export function useModel(
378378

379379
if (options && options.local) {
380380
const proxy = ref<any>(props[name])
381+
watchSyncEffect(() => {
382+
proxy.value = props[name]
383+
})
381384

382385
watch(
383-
() => props[name],
384-
v => (proxy.value = v)
386+
proxy,
387+
value => {
388+
if (value !== props[name]) {
389+
i.emit(`update:${name}`, value)
390+
}
391+
},
392+
{ flush: 'sync' }
385393
)
386394

387-
watch(proxy, value => {
388-
if (value !== props[name]) {
389-
i.emit(`update:${name}`, value)
390-
}
391-
})
392-
393395
return proxy
394396
} else {
395397
return {

0 commit comments

Comments
 (0)