From 42da93d6326def9fa056003e7bd983eb5a9d42b1 Mon Sep 17 00:00:00 2001 From: zongzi531 Date: Wed, 23 Sep 2020 17:34:50 +0800 Subject: [PATCH] Support watch sync mode --- src/vue-property-decorator.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vue-property-decorator.ts b/src/vue-property-decorator.ts index 2e2e159..3851086 100644 --- a/src/vue-property-decorator.ts +++ b/src/vue-property-decorator.ts @@ -228,14 +228,18 @@ export function PropSync( } } +type SupportSyncWatchOptions = WatchOptions & { + sync?: boolean +} + /** * decorator of a watch function * @param path the path or the expression to observe - * @param WatchOption + * @param WatchOption & { sync?: boolean } support watch sync mode. * @return MethodDecorator */ -export function Watch(path: string, options: WatchOptions = {}) { - const { deep = false, immediate = false } = options +export function Watch(path: string, options: SupportSyncWatchOptions = {}) { + const { deep = false, immediate = false, sync = false } = options return createDecorator((componentOptions, handler) => { if (typeof componentOptions.watch !== 'object') { @@ -250,7 +254,7 @@ export function Watch(path: string, options: WatchOptions = {}) { watch[path] = [] } - watch[path].push({ handler, deep, immediate }) + watch[path].push({ handler, deep, immediate, sync }) }) }