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

Function Watcher

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

Source from the content-addressed store, hash-verified

2403 * This is used for both the $watch() api and directives.
2404 */
2405var Watcher = function Watcher (
2406 vm,
2407 expOrFn,
2408 cb,
2409 options
2410) {
2411 this.vm = vm;
2412 vm._watchers.push(this);
2413 // options
2414 if (options) {
2415 this.deep = !!options.deep;
2416 this.user = !!options.user;
2417 this.lazy = !!options.lazy;
2418 this.sync = !!options.sync;
2419 } else {
2420 this.deep = this.user = this.lazy = this.sync = false;
2421 }
2422 this.cb = cb;
2423 this.id = ++uid$2; // uid for batching
2424 this.active = true;
2425 this.dirty = this.lazy; // for lazy watchers
2426 this.deps = [];
2427 this.newDeps = [];
2428 this.depIds = new _Set();
2429 this.newDepIds = new _Set();
2430 this.expression = process.env.NODE_ENV !== 'production'
2431 ? expOrFn.toString()
2432 : '';
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 process.env.NODE_ENV !== '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