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

Function Watcher

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

Source from the content-addressed store, hash-verified

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