]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: use sync watcher for defineModel local mode
authorEvan You <yyx990803@gmail.com>
Tue, 12 Dec 2023 05:49:23 +0000 (13:49 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 12 Dec 2023 05:49:23 +0000 (13:49 +0800)
ref https://github.com/vuejs/rfcs/discussions/503#discussioncomment-7566278

packages/runtime-core/src/apiSetupHelpers.ts

index 2c2f0d8326baae802ef4a65eea58e5bc94b0a108..76c5aef4eafc6f617e731451edb98eb0bf7a04fa 100644 (file)
@@ -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) =>
@@ -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 {