( source: WatchSource<T> | WatchSource<T>[], cb: WatchCallback<T>, options?: WatchOptions )
| 466 | |
| 467 | // implementation |
| 468 | export 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 | |
| 496 | function traverse(value: unknown, seen: Set<unknown> = new Set()) { |
| 497 | if (!isObject(value) || seen.has(value) || rawSet.has(value)) { |
searching dependent graphs…