MCPcopy
hub / github.com/vuejs/composition-api / watch

Function watch

src/apis/watch.ts:468–494  ·  view source on GitHub ↗
(
  source: WatchSource<T> | WatchSource<T>[],
  cb: WatchCallback<T>,
  options?: WatchOptions
)

Source from the content-addressed store, hash-verified

466
467// implementation
468export function watch<T = any>(
469 source: WatchSource<T> | WatchSource<T>[],
470 cb: WatchCallback<T>,
471 options?: WatchOptions
472): WatchStopHandle {
473 let callback: WatchCallback<unknown> | null = null
474 if (isFunction(cb)) {
475 // source watch
476 callback = cb as WatchCallback<unknown>
477 } else {
478 // effect watch
479 if (__DEV__) {
480 warn(
481 `\`watch(fn, options?)\` signature has been moved to a separate API. ` +
482 `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
483 `supports \`watch(source, cb, options?) signature.`
484 )
485 }
486 options = cb as Partial<WatchOptions>
487 callback = null
488 }
489
490 const opts = getWatcherOption(options)
491 const vm = getWatcherVM()
492
493 return createWatcher(vm, source, callback, opts)
494}
495
496function traverse(value: unknown, seen: Set<unknown> = new Set()) {
497 if (!isObject(value) || seen.has(value) || rawSet.has(value)) {

Callers 9

state.spec.jsFile · 0.90
setupFunction · 0.90
watch.spec.jsFile · 0.90
set.spec.tsFile · 0.90
setupFunction · 0.90
del.spec.tsFile · 0.90
apiWatch.spec.tsFile · 0.90
watch.test-d.tsxFile · 0.85

Calls 5

isFunctionFunction · 0.90
warnFunction · 0.90
getWatcherOptionFunction · 0.85
getWatcherVMFunction · 0.85
createWatcherFunction · 0.85

Tested by 2

setupFunction · 0.72
setupFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…