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
  0945be9b_4168_fadf_756e_db366ae055ba["constructor()"]
  4a4a1a4b_f12d_d764_e007_52d21038bc1b["constructor()"]
  4a4a1a4b_f12d_d764_e007_52d21038bc1b -->|calls| 0945be9b_4168_fadf_756e_db366ae055ba
  c595e491_455c_5f96_1a90_ed59c627158b["get()"]
  0945be9b_4168_fadf_756e_db366ae055ba -->|calls| c595e491_455c_5f96_1a90_ed59c627158b
  e0d05b53_bca8_7903_a6c4_2872f7fcacba["recordEffectScope()"]
  0945be9b_4168_fadf_756e_db366ae055ba -->|calls| e0d05b53_bca8_7903_a6c4_2872f7fcacba
  ed6bde39_5ee1_e944_9968_4371147ae4c9["constructor()"]
  0945be9b_4168_fadf_756e_db366ae055ba -->|calls| ed6bde39_5ee1_e944_9968_4371147ae4c9
  style 0945be9b_4168_fadf_756e_db366ae055ba 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

Called By

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the vue codebase.
What does constructor() call?
constructor() calls 3 function(s): constructor, get, recordEffectScope.
What calls constructor()?
constructor() is called by 1 function(s): constructor.

Analyze Your Own Codebase

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

Try Supermodel Free