* Push a watcher into the watcher queue. *将一个观察者推入观察者队列。 * Jobs with duplicate IDs will be skipped unless it's id重复的作业将被跳过,除非是 * pushed when the queue is being flushed. *刷新队列时推送。 * * 将观察者推进 queue 队列中 过滤重复的 id 除非是*刷新队列时推送。
(watcher)
| 4489 | * 将观察者推进 queue 队列中 过滤重复的 id 除非是*刷新队列时推送。 |
| 4490 | */ |
| 4491 | function queueWatcher(watcher) { |
| 4492 | var id = watcher.id; |
| 4493 | if (has[id] == null) { |
| 4494 | has[id] = true; |
| 4495 | // flushing=true; //这个标志需要去掉 |
| 4496 | console.log(flushing) |
| 4497 | |
| 4498 | if (!flushing) { |
| 4499 | queue.push(watcher); //把观察者添加到队列中 |
| 4500 | } else { |
| 4501 | // if already flushing, splice the watcher based on its id 如果已经刷新,则根据监视程序的id拼接它 |
| 4502 | // if already past its id, it will be run next immediately. 如果已经通过了它的id,那么将立即运行next。 |
| 4503 | var i = queue.length - 1; |
| 4504 | while (i > index && queue[i].id > watcher.id) { |
| 4505 | i--; |
| 4506 | } |
| 4507 | //根据id大小拼接插入在数组的哪个位置 |
| 4508 | queue.splice(i + 1, 0, watcher); |
| 4509 | } |
| 4510 | console.log(waiting) |
| 4511 | |
| 4512 | // queue the flush |
| 4513 | if (!waiting) { |
| 4514 | waiting = true; |
| 4515 | //为callbacks 收集队列cb 函数 并且根据 pending 状态是否要触发callbacks 队列函数 |
| 4516 | nextTick( |
| 4517 | flushSchedulerQueue//更新观察者 运行观察者watcher.run() 函数 并且 调用组件更新和激活的钩子 |
| 4518 | ); |
| 4519 | } |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | /* */ |
| 4524 |