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

Function Watcher

static/vuejs/vue.common.js:2407–2453  ·  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 = process.env.NODE_ENV !== 'production'
2433 ? expOrFn.toString()
2434 : '';
2435 // parse expression for getter
2436 if (typeof expOrFn === 'function') {
2437 this.getter = expOrFn;
2438 } else {
2439 this.getter = parsePath(expOrFn);
2440 if (!this.getter) {
2441 this.getter = function () {};
2442 process.env.NODE_ENV !== 'production' && warn(
2443 "Failed watching path: \"" + expOrFn + "\" " +
2444 'Watcher only accepts simple dot-delimited paths. ' +
2445 'For full control, use a function instead.',
2446 vm
2447 );
2448 }
2449 }
2450 this.value = this.lazy
2451 ? undefined
2452 : this.get();
2453};
2454
2455/**
2456 * 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