Home / Class/ Dep Class — vue Architecture

Dep Class — vue Architecture

Architecture documentation for the Dep class in dep.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  6468b0c5_2298_434f_d55a_c498376ea8cd["Dep"]
  e5c4d6ab_2495_a6d4_d962_9d9f71bf3114["dep.ts"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|defined in| e5c4d6ab_2495_a6d4_d962_9d9f71bf3114
  c4420842_db23_0c87_a912_08114ff65982["constructor()"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|method| c4420842_db23_0c87_a912_08114ff65982
  61024290_1455_7ebc_3d92_6fd32b0f8fa5["addSub()"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|method| 61024290_1455_7ebc_3d92_6fd32b0f8fa5
  e0646fc5_8798_3487_e9e9_047d883eae08["removeSub()"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|method| e0646fc5_8798_3487_e9e9_047d883eae08
  dd2ea478_4454_41dd_4f1c_546901e17ce6["depend()"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|method| dd2ea478_4454_41dd_4f1c_546901e17ce6
  98344c54_4454_3804_84b6_6f45b28782b9["notify()"]
  6468b0c5_2298_434f_d55a_c498376ea8cd -->|method| 98344c54_4454_3804_84b6_6f45b28782b9

Relationship Graph

Source Code

src/core/observer/dep.ts lines 31–92

export default class Dep {
  static target?: DepTarget | null
  id: number
  subs: Array<DepTarget | null>
  // pending subs cleanup
  _pending = false

  constructor() {
    this.id = uid++
    this.subs = []
  }

  addSub(sub: DepTarget) {
    this.subs.push(sub)
  }

  removeSub(sub: DepTarget) {
    // #12696 deps with massive amount of subscribers are extremely slow to
    // clean up in Chromium
    // to workaround this, we unset the sub for now, and clear them on
    // next scheduler flush.
    this.subs[this.subs.indexOf(sub)] = null
    if (!this._pending) {
      this._pending = true
      pendingCleanupDeps.push(this)
    }
  }

  depend(info?: DebuggerEventExtraInfo) {
    if (Dep.target) {
      Dep.target.addDep(this)
      if (__DEV__ && info && Dep.target.onTrack) {
        Dep.target.onTrack({
          effect: Dep.target,
          ...info
        })
      }
    }
  }

  notify(info?: DebuggerEventExtraInfo) {
    // stabilize the subscriber list first
    const subs = this.subs.filter(s => s) as DepTarget[]
    if (__DEV__ && !config.async) {
      // subs aren't sorted in scheduler if not running async
      // we need to sort them now to make sure they fire in correct
      // order
      subs.sort((a, b) => a.id - b.id)
    }
    for (let i = 0, l = subs.length; i < l; i++) {
      const sub = subs[i]
      if (__DEV__ && info) {
        sub.onTrigger &&
          sub.onTrigger({
            effect: subs[i],
            ...info
          })
      }
      sub.update()
    }
  }
}

Domain

Frequently Asked Questions

What is the Dep class?
Dep is a class in the vue codebase, defined in src/core/observer/dep.ts.
Where is Dep defined?
Dep is defined in src/core/observer/dep.ts at line 31.

Analyze Your Own Codebase

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

Try Supermodel Free