MCPcopy Create free account
hub / github.com/ygs-code/vue / flushSchedulerQueue

Function flushSchedulerQueue

vue.js:4385–4448  ·  view source on GitHub ↗

* Flush both queues and run the watchers. 刷新两个队列并运行监视程序。 * 更新观察者 运行观察者watcher.run() 函数 并且 调用组件更新和激活的钩子

()

Source from the content-addressed store, hash-verified

4383 * 更新观察者 运行观察者watcher.run() 函数 并且 调用组件更新和激活的钩子
4384 */
4385 function flushSchedulerQueue() {
4386 flushing = true;
4387 var watcher, id;
4388
4389 // Sort queue before flush.
4390 // This ensures that:
4391 // 1. Components are updated from parent to child. (because parent is always
4392 // created before the child)
4393 // 2. A component's user watchers are run before its render watcher (because
4394 // user watchers are created before the render watcher)
4395 // 3. If a component is destroyed during a parent component's watcher run,
4396 // its watchers can be skipped.
4397 //刷新前对队列排序。
4398 //这确保:
4399 // 1。组件从父组件更新到子组件。因为父母总是在孩子之前创建)
4400 // 2。组件的用户观察者在其呈现观察者之前运行(因为用户观察者是在渲染观察者之前创建的)
4401 // 3。如果一个组件在父组件的监视程序运行期间被销毁,可以跳过它的观察者。
4402 //观察者根据id去排序
4403 queue.sort(function (a, b) {
4404 return a.id - b.id;
4405 });
4406
4407 // do not cache length because more watchers might be pushed 不要缓存长度,因为可能会推入更多的观察者
4408 // as we run existing watchers 我们运行现有的观察者
4409 for (index = 0; index < queue.length; index++) {
4410 watcher = queue[index]; //获取单个观察者
4411 id = watcher.id;
4412 has[id] = null;
4413 watcher.run(); //运行观察者
4414 // in dev build, check and stop circular updates. 在dev build中,检查并停止循环更新。
4415 if ("development" !== 'production' && has[id] != null) {
4416 circular[id] = (circular[id] || 0) + 1;
4417 if (circular[id] > MAX_UPDATE_COUNT) {
4418 warn(
4419 'You may have an infinite update loop ' + (
4420 watcher.user
4421 ? ("in watcher with expression \"" + (watcher.expression) + "\"")
4422 : "in a component render function."
4423 ),
4424 watcher.vm
4425 );
4426 break
4427 }
4428 }
4429 }
4430
4431 // keep copies of post queues before resetting state 在重置状态之前保留post队列的副本
4432 var activatedQueue = activatedChildren.slice(); // 浅拷贝
4433 var updatedQueue = queue.slice();// 浅拷贝
4434
4435 //清空观察者watcher队列中的数据
4436 resetSchedulerState();
4437
4438 // call component updated and activated hooks 调用组件更新和激活的钩子
4439 callActivatedHooks(activatedQueue);
4440 callUpdatedHooks(updatedQueue);
4441
4442 // devtool hook

Callers

nothing calls this directly

Calls 3

resetSchedulerStateFunction · 0.85
callActivatedHooksFunction · 0.85
callUpdatedHooksFunction · 0.85

Tested by

no test coverage detected