| 5116 | |
| 5117 | //创建计算属性 获取值 收集 dep 依赖 |
| 5118 | function createComputedGetter(key) { |
| 5119 | return function computedGetter() { |
| 5120 | // Watcher 实例化之后的对象 |
| 5121 | var watcher = this._computedWatchers && this._computedWatchers[key]; |
| 5122 | if (watcher) { |
| 5123 | if (watcher.dirty) { |
| 5124 | //this.value 获取值 this.getter |
| 5125 | watcher.evaluate(); //评估 |
| 5126 | } |
| 5127 | if (Dep.target) { |
| 5128 | //为Watcher 添加 为Watcher.newDeps.push(dep); 一个dep对象 |
| 5129 | //循环deps 收集 newDeps dep 当newDeps 数据被清空的时候重新收集依赖 |
| 5130 | watcher.depend(); |
| 5131 | } |
| 5132 | //返回值 |
| 5133 | return watcher.value |
| 5134 | } |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | //初始化事件Methods 把事件 冒泡到 vm[key] 虚拟dom 最外层中 |
| 5139 | function initMethods(vm, methods) { |