Skip to content

Instantly share code, notes, and snippets.

@superMDguy
Last active November 9, 2017 21:50
Show Gist options
  • Save superMDguy/9d69b36fef029539683b3fee16171992 to your computer and use it in GitHub Desktop.
Save superMDguy/9d69b36fef029539683b3fee16171992 to your computer and use it in GitHub Desktop.
// See https://github.com/vuejs/vue/blob/be9ac624c81bb698ed75628fe0cbeaba4a2fc991/src/core/observer/dep.js
// for full implementation
class Dep {
constructor() {
this.subs = new Set()
}
addSub(sub) {
this.subs.add(sub)
}
depend() {
if (Dep.target) {
Dep.target.addDep(this)
}
}
notify() {
this.subs.forEach(sub => sub.update())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment