MCPcopy Create free account
hub / github.com/TruthHun/BookStack / Watcher

Function Watcher

static/vuejs/vue.runtime.common.js:2403–2449  ·  view source on GitHub ↗
(
  vm,
  expOrFn,
  cb,
  options
)

Source from the content-addressed store, hash-verified

2401 * This is used for both the $watch() api and directives.
2402 */
2403var Watcher = function Watcher (
2404 vm,
2405 expOrFn,
2406 cb,
2407 options
2408) {
2409 this.vm = vm;
2410 vm._watchers.push(this);
2411 // options
2412 if (options) {
2413 this.deep = !!options.deep;
2414 this.user = !!options.user;
2415 this.lazy = !!options.lazy;
2416 this.sync = !!options.sync;
2417 } else {
2418 this.deep = this.user = this.lazy = this.sync = false;
2419 }
2420 this.cb = cb;
2421 this.id = ++uid$2; // uid for batching
2422 this.active = true;
2423 this.dirty = this.lazy; // for lazy watchers
2424 this.deps = [];
2425 this.newDeps = [];
2426 this.depIds = new _Set();
2427 this.newDepIds = new _Set();
2428 this.expression = process.env.NODE_ENV !== 'production'
2429 ? expOrFn.toString()
2430 : '';
2431 // parse expression for getter
2432 if (typeof expOrFn === 'function') {
2433 this.getter = expOrFn;
2434 } else {
2435 this.getter = parsePath(expOrFn);
2436 if (!this.getter) {
2437 this.getter = function () {};
2438 process.env.NODE_ENV !== 'production' && warn(
2439 "Failed watching path: \"" + expOrFn + "\" " +
2440 'Watcher only accepts simple dot-delimited paths. ' +
2441 'For full control, use a function instead.',
2442 vm
2443 );
2444 }
2445 }
2446 this.value = this.lazy
2447 ? undefined
2448 : this.get();
2449};
2450
2451/**
2452 * Evaluate the getter, and re-collect dependencies.

Callers

nothing calls this directly

Calls 3

parsePathFunction · 0.70
warnFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected