/*@flow*/Import type Watcher from'./watcher 'Import {Remove} from‘.. /util/index 'Let uid= 0/** * A DEP is A observable that can has multiple * directives subscribing to it.
*/Exportdefaultclass Dep {static target:?watcher; Id:number; Subs:array<Watcher>; Constructor () { This. id = uid++ This. Subs =[]} addSub (sub:watcher) { This. Subs.push (sub)} removesub (Sub:watcher) {Remove ( This. Subs, Sub)} Depend () {if(dep.target) {Dep.target.addDep ( This)}} notify () {//stabilize the Subscriber list first to avoid changes affecting the original arrayConst SUBS = This. Subs.slice ()
for(Let i = 0, L = subs.length; i < L; i++) {subs[i].update () }}}//The current target watcher being evaluated.//This is globally unique because there could are only one//Watcher being evaluated at any time.Dep.target =NULLConst Targetstack=[]exportfunctionPushtarget (_target:watcher) {if(Dep.target) Targetstack.push (dep.target) Dep.target=_target}exportfunctionPoptarget () {Dep.target=targetstack.pop ()}
Vue.js Source Code Learning Note-----DEP