Skip to content

Commit

Permalink
perf: use sync watcher for defineModel local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 12, 2023
1 parent 70eca21 commit 7e60d10
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { warn } from './warning'
import { SlotsType, StrictUnwrapSlotsType } from './componentSlots'
import { Ref, ref } from '@vue/reactivity'
import { watch } from './apiWatch'
import { watch, watchSyncEffect } from './apiWatch'

// dev only
const warnRuntimeUsage = (method: string) =>
Expand Down Expand Up @@ -378,18 +378,20 @@ export function useModel(

if (options && options.local) {
const proxy = ref<any>(props[name])
watchSyncEffect(() => {
proxy.value = props[name]
})

watch(
() => props[name],
v => (proxy.value = v)
proxy,
value => {
if (value !== props[name]) {
i.emit(`update:${name}`, value)
}
},
{ flush: 'sync' }
)

watch(proxy, value => {
if (value !== props[name]) {
i.emit(`update:${name}`, value)
}
})

return proxy
} else {
return {
Expand Down

0 comments on commit 7e60d10

Please sign in to comment.