Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Support watch sync mode. #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/vue-property-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 })
})
}

Expand Down