feat(runtime-core): add watchEffect API
BREAKING CHANGE: replae `watch(fn, options?)` with `watchEffect`
The `watch(fn, options?)` signature has been replaced by the new
`watchEffect` API, which has the same usage and behavior. `watch`
now only supports the `watch(source, cb, options?)` signautre.
This commit is contained in:
@@ -71,6 +71,14 @@ export type StopHandle = () => void
|
||||
|
||||
const invoke = (fn: Function) => fn()
|
||||
|
||||
// Simple effect.
|
||||
export function watchEffect(
|
||||
effect: WatchEffect,
|
||||
options?: BaseWatchOptions
|
||||
): StopHandle {
|
||||
return doWatch(effect, null, options)
|
||||
}
|
||||
|
||||
// initial value for watchers to trigger on undefined initial values
|
||||
const INITIAL_WATCHER_VALUE = {}
|
||||
|
||||
@@ -110,6 +118,13 @@ export function watch<T = any>(
|
||||
// watch(source, cb)
|
||||
return doWatch(effectOrSource, cbOrOptions, options)
|
||||
} else {
|
||||
// TODO remove this in the next release
|
||||
__DEV__ &&
|
||||
warn(
|
||||
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
||||
`Use \`watchEffect(fn, options?)\` instead. \`watch\` will only ` +
|
||||
`support \`watch(source, cb, options?) signature in the next release.`
|
||||
)
|
||||
// watch(effect)
|
||||
return doWatch(effectOrSource, null, cbOrOptions)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export {
|
||||
markNonReactive
|
||||
} from '@vue/reactivity'
|
||||
export { computed } from './apiComputed'
|
||||
export { watch } from './apiWatch'
|
||||
export { watch, watchEffect } from './apiWatch'
|
||||
export {
|
||||
onBeforeMount,
|
||||
onMounted,
|
||||
|
||||
Reference in New Issue
Block a user