响应式系统
响应式对象
Observer
依赖收集
属性 getter —> Dep.append —> Watcher.addDep
更新派发
属性 setter —> Dep.notify —> Watcher.update —> queueWatcher
queueWatcher
- watcher id 去重
- 在队列未执行时,直接推入队列;否则通过 watcher id 将 该 watcher 放入 queue,但是如果此时执行已经过了他的 id,则会轮到下一次执行
- 通过 waiting 来控制
nextTick(flushSchedulerQueue)
flushSchedulerQueue
- 队列根据 watcher id 排序(增序)
- 保证父执行先于子
- 自定义 watcher 优先于 render Watcher
如果父组件内把子组件删除后,则子组件可无需执行
- 循环执行,在执行前运行 before 钩子
- 运行生命周期钩子,包含 activated 和 updated
nextTick
- nextTick 包含自身的队列,callbacks
- 通过对 Promise,MutationObserver,setImmediate,setTimeout 来判断执行队列函数 timerFunc,timerFunc 执行时,执行 callbacks
让 nextTick 队列运行编程异步任务