Vue.js Source Code Learning Note-----DEP

Source: Internet
Author: User

/*@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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.