Home / Function/ constructor() — vue Function Reference

constructor() — vue Function Reference

Architecture documentation for the constructor() function in watcher.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  a722da6d_3b55_7364_ef37_4ef6a7eeebfe["constructor()"]
  6447431e_6924_8ca8_071d_44b55ba081b1["Watcher"]
  a722da6d_3b55_7364_ef37_4ef6a7eeebfe -->|defined in| 6447431e_6924_8ca8_071d_44b55ba081b1
  9af667fb_20e8_0763_f10d_d63da0255ba8["get()"]
  a722da6d_3b55_7364_ef37_4ef6a7eeebfe -->|calls| 9af667fb_20e8_0763_f10d_d63da0255ba8
  c4420842_db23_0c87_a912_08114ff65982["constructor()"]
  a722da6d_3b55_7364_ef37_4ef6a7eeebfe -->|calls| c4420842_db23_0c87_a912_08114ff65982
  style a722da6d_3b55_7364_ef37_4ef6a7eeebfe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/observer/watcher.ts lines 67–128

  constructor(
    vm: Component | null,
    expOrFn: string | (() => any),
    cb: Function,
    options?: WatcherOptions | null,
    isRenderWatcher?: boolean
  ) {
    recordEffectScope(
      this,
      // if the active effect scope is manually created (not a component scope),
      // prioritize it
      activeEffectScope && !activeEffectScope._vm
        ? activeEffectScope
        : vm
        ? vm._scope
        : undefined
    )
    if ((this.vm = vm) && isRenderWatcher) {
      vm._watcher = this
    }
    // options
    if (options) {
      this.deep = !!options.deep
      this.user = !!options.user
      this.lazy = !!options.lazy
      this.sync = !!options.sync
      this.before = options.before
      if (__DEV__) {
        this.onTrack = options.onTrack
        this.onTrigger = options.onTrigger
      }
    } else {
      this.deep = this.user = this.lazy = this.sync = false
    }
    this.cb = cb
    this.id = ++uid // uid for batching
    this.active = true
    this.post = false
    this.dirty = this.lazy // for lazy watchers
    this.deps = []
    this.newDeps = []
    this.depIds = new Set()
    this.newDepIds = new Set()
    this.expression = __DEV__ ? expOrFn.toString() : ''
    // parse expression for getter
    if (isFunction(expOrFn)) {
      this.getter = expOrFn
    } else {
      this.getter = parsePath(expOrFn)
      if (!this.getter) {
        this.getter = noop
        __DEV__ &&
          warn(
            `Failed watching path: "${expOrFn}" ` +
              'Watcher only accepts simple dot-delimited paths. ' +
              'For full control, use a function instead.',
            vm
          )
      }
    }
    this.value = this.lazy ? undefined : this.get()
  }

Domain

Subdomains

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the vue codebase, defined in src/core/observer/watcher.ts.
Where is constructor() defined?
constructor() is defined in src/core/observer/watcher.ts at line 67.
What does constructor() call?
constructor() calls 2 function(s): constructor, get.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free