-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(watchOnce): use vue's native once behaviour #4750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
export function watchOnce<T = any>(source: T, cb: any, options?: Omit<WatchOptions, 'once'>) { | ||
return watch( | ||
source as any, | ||
cb, | ||
{ | ||
...options, | ||
once: true, | ||
}, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function watchOnce<T = any>(source: T, cb: any, options?: Omit<WatchOptions, 'once'>) { | |
return watch( | |
source as any, | |
cb, | |
{ | |
...options, | |
once: true, | |
}, | |
) | |
} | |
export function watchOnce<T = any, Immediate extends Readonly<boolean> = false>(source: T | WatchSource<T>, cb: any, options?: Omit<WatchOptions<Immediate>, 'once'>) { | |
return watch( | |
source, | |
cb, | |
{ | |
...options, | |
once: true, | |
}, | |
) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OrbisK Why? To keep compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, and to be as close as possible to native watch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need to, but maybe we want to overload like vue does:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OrbisK Shall we do the same with the other watch shortcuts I guess.
I wonder as well why we don't do rest parameters and typeof watch
(with a tail-like helper like the ones in type-fest
to overwrite just the last parameter) so we don't have to keep this up to date ever...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do, but does this work with the generics and overloads?
Yes we are requiring 3.5.0+, so it should be fine to do this |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Updates
watchOnce
logic to match shortcut watchers likewatchImmediate
, so it works as a pure shortcut to Vue's native once watchers feature.Additional context
@antfu This requires Vue 3.4, so technically this is a breaking change for users pre-Vue 3.4. Shall we support users staying behind or users are expected to always be in the latest version? According to our semver range, Vue 3.5 is the only supported version, but I don't know if this is intended or not.