MCPcopy
hub / github.com/vuejs/core / instanceWatch

Function instanceWatch

packages/runtime-core/src/apiWatch.ts:245–268  ·  view source on GitHub ↗
(
  this: ComponentInternalInstance,
  source: string | Function,
  value: WatchCallback | ObjectWatchOptionItem,
  options?: WatchOptions,
)

Source from the content-addressed store, hash-verified

243
244// this.$watch
245export function instanceWatch(
246 this: ComponentInternalInstance,
247 source: string | Function,
248 value: WatchCallback | ObjectWatchOptionItem,
249 options?: WatchOptions,
250): WatchHandle {
251 const publicThis = this.proxy
252 const getter = isString(source)
253 ? source.includes('.')
254 ? createPathGetter(publicThis!, source)
255 : () => publicThis![source as keyof typeof publicThis]
256 : source.bind(publicThis, publicThis)
257 let cb
258 if (isFunction(value)) {
259 cb = value
260 } else {
261 cb = value.handler as Function
262 options = value
263 }
264 const reset = setCurrentInstance(this)
265 const res = doWatch(getter, cb.bind(publicThis), options)
266 reset()
267 return res
268}
269
270export function createPathGetter(
271 ctx: ComponentPublicInstance,

Callers

nothing calls this directly

Calls 6

isStringFunction · 0.90
isFunctionFunction · 0.90
setCurrentInstanceFunction · 0.90
createPathGetterFunction · 0.85
doWatchFunction · 0.85
resetFunction · 0.50

Tested by

no test coverage detected