(
vm, //vm dom
expOrFn, //获取值的函数,或者是更新viwe试图函数
cb, //回调函数,回调值给回调函数
options, //参数
isRenderWatcher//是否渲染过得观察者
)
| 4534 | * 当前vue实例、updateComponent函数、空函数。 |
| 4535 | */ |
| 4536 | var Watcher = function Watcher( |
| 4537 | vm, //vm dom |
| 4538 | expOrFn, //获取值的函数,或者是更新viwe试图函数 |
| 4539 | cb, //回调函数,回调值给回调函数 |
| 4540 | options, //参数 |
| 4541 | isRenderWatcher//是否渲染过得观察者 |
| 4542 | ) { |
| 4543 | console.log('====Watcher====') |
| 4544 | this.vm = vm; |
| 4545 | //是否是已经渲染过得观察者 |
| 4546 | if (isRenderWatcher) { //把当前 Watcher 对象赋值给 vm._watcher上 |
| 4547 | vm._watcher = this; |
| 4548 | } |
| 4549 | //把观察者添加到队列里面 当前Watcher添加到vue实例上 |
| 4550 | vm._watchers.push(this); |
| 4551 | // options |
| 4552 | if (options) { //如果有参数 |
| 4553 | this.deep = !!options.deep; //实际 |
| 4554 | this.user = !!options.user; //用户 |
| 4555 | this.lazy = !!options.lazy; //懒惰 ssr 渲染 |
| 4556 | this.sync = !!options.sync; //如果是同步 |
| 4557 | } else { |
| 4558 | |
| 4559 | this.deep = this.user = this.lazy = this.sync = false; |
| 4560 | } |
| 4561 | this.cb = cb; //回调函数 |
| 4562 | this.id = ++uid$1; // uid for batching uid为批处理 监听者id |
| 4563 | this.active = true; //激活 |
| 4564 | this.dirty = this.lazy; // for lazy watchers 对于懒惰的观察者 |
| 4565 | this.deps = []; // 观察者队列 |
| 4566 | this.newDeps = []; // 新的观察者队列 |
| 4567 | // 内容不可重复的数组对象 |
| 4568 | this.depIds = new _Set(); |
| 4569 | this.newDepIds = new _Set(); |
| 4570 | // 把函数变成字符串形式 |
| 4571 | this.expression = expOrFn.toString(); |
| 4572 | // parse expression for getter |
| 4573 | //getter的解析表达式 |
| 4574 | if (typeof expOrFn === 'function') { |
| 4575 | //获取值的函数 |
| 4576 | this.getter = expOrFn; |
| 4577 | } else { |
| 4578 | //如果是keepAlive 组件则会走这里 |
| 4579 | //path 因该是路由地址 |
| 4580 | if (bailRE.test(path)) { // 匹配上 返回 true var bailRE = /[^\w.$]/; //匹配不是 数字字母下划线 $符号 开头的为true |
| 4581 | return |
| 4582 | } |
| 4583 | |
| 4584 | // //匹配不上 path在已点分割 |
| 4585 | // var segments = path.split('.'); |
| 4586 | // return function (obj) { |
| 4587 | // |
| 4588 | // for (var i = 0; i < segments.length; i++) { |
| 4589 | // //如果有参数则返回真 |
| 4590 | // if (!obj) { |
| 4591 | // return |
| 4592 | // } |
| 4593 | // //将对象中的一个key值 赋值给该对象 相当于 segments 以点拆分的数组做obj 的key |
nothing calls this directly
no test coverage detected