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

Function Watcher

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

Source from the content-addressed store, hash-verified

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