我已经阅读了关于这个主题的那篇文章(ZoneJS和Angular2区域的文章),但仍然有一个术语我找不到任何定义.
这是this帖子的摘录:
NgZone is basically a forked zone that extends its API and adds some
additional functionality to its execution context. One of the things
it adds to the API is the following set of custom events we can
subscribe to,as they are observable streams:onTurnStart() – Notifies
subscribers just before Angular’s event turn starts. Emits an event
once per browser task that is handled by Angular.onTurnDone() –
Notifies subscribers immediately after Angular’s zone is done
processing the current turn and any micro tasks scheduled from that
turn.onEventDone() – Notifies subscribers immediately after the final onTurnDone() callback before ending VM event. Useful for testing to
validate application state
我理解一个区域的概念,它可以分叉,我唯一的问题是VM转向和VM事件,我找不到任何定义.
这些VM事件和转弯是什么?他们是ZoneJS,Angular还是浏览器的一部分?
谢谢,Avi.
解决方法
当然,还阅读了Dylan Meeus给我的链接:What are zone turns?
这就是我现在所理解的这些术语的含义:
VM turn =浏览器任务 – 由堆栈清除时运行的某些浏览器事件循环(例如setTimout队列)处理的回调.
VM事件 – 浏览器处理所有待处理任务的操作.
Microtask – 正如上面链接的帖子中所描述的那样,这些回调是根据HTML规范,不应该出于性能原因(例如承诺和观察者)被安排为任务,因此它们被安排为称为微任务的东西.
微任务进入其自己的特殊队列,该队列在每个回调或任务结束时运行,这意味着如果任务调度微任务,则该微任务将在该任务结束时运行,阻止当时在队列中等待的任何任务.
我希望这可以帮助别人 :)