@@ -37,9 +37,9 @@ const sharedPropertyDefinition = {
3737
3838/**
3939 * 代理函数,app._data.text -> app.text
40- * @param {* } target
41- * @param {* } sourceKey
42- * @param {* } key
40+ * @param {* } target
41+ * @param {* } sourceKey
42+ * @param {* } key
4343 */
4444
4545// proxy(vm, `_props`, key)
@@ -70,6 +70,8 @@ export function initState (vm: Component) {
7070}
7171
7272function initProps ( vm : Component , propsOptions : Object ) {
73+
74+ // 获取props的数据
7375 const propsData = vm . $options . propsData || { }
7476 const props = vm . _props = { }
7577 // cache prop keys so that future props updates can iterate using Array
@@ -200,23 +202,7 @@ function initComputed (vm: Component, computed: Object) {
200202
201203 if ( ! isSSR ) {
202204 // create internal watcher for the computed property.
203- /**
204- * 熟悉的new Watcher,创建一个订阅者,为了之后收集依赖
205- * 将例子中的num、lastNum和计算属性comNum进行绑定
206- * 也就是说在一个deps中有两个dep,其中的subs分别是
207- * dep1.subs:[watcher(num),watcher(comNum)]
208- * dep2.subs:[watcher(lastNum),watcher(comNum)]
209- * dep3........
210- * 请看前面的例子,页面html中并没有渲染{{lastNum}};按理说就不会执行lastNum的getter
211- * 从而就不会和计算属性进行关联绑定,如果更改lastNum就不会触发dep2的notify()发布
212- * 自然也就不会在页面看到comNum有所变化,但是运行后却不是这样,为什么呢
213- * 这就引出这个initComputed的下面方法了---依赖收集(watcher.prototype.depend)!
214- * 当时也是看了好久才知道这个depend方法的作用,后面再说
215- * 首先先来提个头,就是下面代码中watcher中这个getter
216- * 其实就是function comNum() {return this.num+"-computed-"+this.lastNum;}}
217- * 而这个getter什么时候执行呢,会在Watcher.prototype.evaluate()方法中执行
218- * 所以watcher中的evaluate()与depend()两个方法都与initComputed相关
219- */
205+ // computed watcher
220206 watchers [ key ] = new Watcher (
221207 vm ,
222208 getter || noop ,
0 commit comments