- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Vue 源码解析:深入响应式原理(下)
Vue 源码解析:深入响应式原理(下)?Watcher我们先来看一下 Watcher 类的实现,它的源码定义如下:!-源码目录:src/watcher.js--export default function Watcher (vm, expOrFn, cb, options) { // mix in options if (options) { extend(this, options) } var isFn = typeof expOrFn === function this.vm = vm vm._watchers.push(this) this.expression = expOrFn this.cb = cb this.id = ++uid // uid for batching this.active = true this.dirty = this.lazy // for lazy watchers this.deps = [] this.newDeps = [] this.depIds = new Set() this.newDepIds = new Set() this.prevError = null // for async error stacks // parse expression for getter/setter if (isFn) { this.getter = expOrFn this.setter = undefined } else { var res = parseExpression(expOrFn, this.twoWay) this.getter = res.get this.setter = res.set } this.value = this.lazy ? undefined : this.get() // state for avoiding false triggers for deep and Array // watchers during vm._digest() this.queued = this.shallow = false}Directive 实例在初始化 Watche r时,会传入指令的 expression。Watcher 构造函数会通过 parseExpression(expOrFn, this.twoWay) 方法对 expression 做进一步的解析。在前面的例子中, expression 是times,passExpression 方法的功能是把 expression 转换成一个对象,如下图所示:可以看到 res 有两个属性,其中 exp 为表达式字符串;get 是通过 new Function 生成的匿名方法,可以把它打印出来,如下图所示:可以看到 res.get 方法很简单,它接受传入一个 scope 变量,返回 scope.times。对于传入的 scope 值,稍后我们会进行介绍。在 Watcher 构造函数的最后调用了 this.get 方法,它的源码定义如下:!-源码目录:src/watcher.js--Watcher.prototype.get = function () { this.beforeGet() var scope = this.scope || this.vm var value try { value = this.getter.call(scope, scope) } catch (e) { if ( process.env.NODE_ENV !== production config.warnExpressionErrors ) { warn( Error when evaluating expression + + this.expression + : + e.toString(), this.vm ) } } // touch every property so they are all tracked as // dependencies for deep watching if (this.deep) { traverse(value) } if (this.preProcess) { value = this.preProcess(value) } if (this.filters) { value = scope._applyFilters(
您可能关注的文档
- 男儿当自强 A Man‘s A Man For A’ That 罗伯特彭斯.doc
- 初中升高中,学校自主招生选拔考试 英语试题.doc
- Java中Native的使用.docx
- 保送考试高三英语新概念46--50单词整理.docx
- 高一英语Book4 Unit 1 Women of achievement.doc
- 2007年西班牙语专业四级笔试试题(部分答案).doc
- 茶的产地和品种2.doc
- 2011年职称英语综合A类真题及答案解析(最全).docx
- 2014-07-26 Native VLAN 的理解.doc
- 基础西班牙语短语.docx
- 北语201109考试批次-综合英语(III)模拟试卷三.doc
- 1Windows Phone,Windows Mobile,Windows Embedded CE(WinCE),.NET Compact Framework,Native C++开发系列(.docx
- 9312配置20150815.docx
- 2016九年级英语模拟卷.doc
- 美国西海岸10日自驾游完整攻略之Yosemite National Park篇.doc
- 必修2Module 4Fine Arts-Western,Chinese andPop Arts.doc
- 2008年12月大学英语六级(CET-6)真题试卷(含答案和听力原文).doc
- 游戏控制器发展及Kinect底座拆解.doc
- 英语单词模块一到五纯英文.docx
- 谷歌计划在印度开设Android Nation 零售实体店.doc
文档评论(0)