Dep Class — vue Architecture
Architecture documentation for the Dep class in dep.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD 485177ad_539e_577c_6503_821a3b761eff["Dep"] dfb2b3e1_ffba_6029_124e_b43a30f0f999["dep.ts"] 485177ad_539e_577c_6503_821a3b761eff -->|defined in| dfb2b3e1_ffba_6029_124e_b43a30f0f999 f85018be_e0a0_2003_eea0_3ff58670fc4b["constructor()"] 485177ad_539e_577c_6503_821a3b761eff -->|method| f85018be_e0a0_2003_eea0_3ff58670fc4b 4129cde1_8b3e_bdac_5d0f_f5cb3925e918["addSub()"] 485177ad_539e_577c_6503_821a3b761eff -->|method| 4129cde1_8b3e_bdac_5d0f_f5cb3925e918 6dd1ab57_f5b5_94ab_fab6_34852abb2663["removeSub()"] 485177ad_539e_577c_6503_821a3b761eff -->|method| 6dd1ab57_f5b5_94ab_fab6_34852abb2663 127eb37f_bb82_724e_10d1_24e519f60aab["depend()"] 485177ad_539e_577c_6503_821a3b761eff -->|method| 127eb37f_bb82_724e_10d1_24e519f60aab 399dccff_c2d5_9afe_7a83_39f1cdff28f7["notify()"] 485177ad_539e_577c_6503_821a3b761eff -->|method| 399dccff_c2d5_9afe_7a83_39f1cdff28f7
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
Defined In
Source
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