angular2 了解 VM 转向和事件
angular2 understanding VM turns and events
我刚刚开始研究 Angular2 变更检测机制。
我已经阅读了 Thoughram 关于该主题的博客 posts(关于 ZoneJS 和 Angular2 区域的博客),但仍然有 1 个术语我找不到任何定义。
以下是 this post 的摘录:
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 turn
和 VM event
,我找不到任何定义。
这些 VM 事件和回合是什么?它们是 ZoneJS 的一部分,Angular 还是仅仅是浏览器?
谢谢,阿维。
如果有人对答案感兴趣,这对我来说很清楚:https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
当然也看了link Dylan Meeus给我的:
这就是我现在对这些术语的理解:
VM turn = 浏览器任务 - 由某些浏览器事件循环(例如 setTimout 队列)处理的回调,当堆栈清除时 运行。
VM 事件 - 浏览器处理所有待处理任务的操作。
微任务——如上文 post link 中所述,根据 HTML 规范,出于性能原因,这些回调不应被安排为任务(例如 promises 和 observers),因此它们被安排为称为微任务的东西。
一个微任务在每个回调或任务结束时进入它自己的特殊队列运行,这意味着如果一个任务调度一个微任务,该微任务将在该任务结束时运行,阻塞任何任务当时在排队。
自2.0.0-beta.10版本开始,onTurnStart、onTurnDone、onEventDone这三个方法重命名如下(CHANGELOG.md):
NgZone.onTurnStart => NgZone.onUnstable
NgZone.onTurnDone => NgZone.onMicrotaskEmpty
NgZone.onEventDone => NgZone.onStable
新名字好多了。
我刚刚开始研究 Angular2 变更检测机制。
我已经阅读了 Thoughram 关于该主题的博客 posts(关于 ZoneJS 和 Angular2 区域的博客),但仍然有 1 个术语我找不到任何定义。
以下是 this post 的摘录:
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 turn
和 VM event
,我找不到任何定义。
这些 VM 事件和回合是什么?它们是 ZoneJS 的一部分,Angular 还是仅仅是浏览器?
谢谢,阿维。
如果有人对答案感兴趣,这对我来说很清楚:https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
当然也看了link Dylan Meeus给我的:
这就是我现在对这些术语的理解:
VM turn = 浏览器任务 - 由某些浏览器事件循环(例如 setTimout 队列)处理的回调,当堆栈清除时 运行。
VM 事件 - 浏览器处理所有待处理任务的操作。
微任务——如上文 post link 中所述,根据 HTML 规范,出于性能原因,这些回调不应被安排为任务(例如 promises 和 observers),因此它们被安排为称为微任务的东西。 一个微任务在每个回调或任务结束时进入它自己的特殊队列运行,这意味着如果一个任务调度一个微任务,该微任务将在该任务结束时运行,阻塞任何任务当时在排队。
自2.0.0-beta.10版本开始,onTurnStart、onTurnDone、onEventDone这三个方法重命名如下(CHANGELOG.md):
NgZone.onTurnStart => NgZone.onUnstable
NgZone.onTurnDone => NgZone.onMicrotaskEmpty
NgZone.onEventDone => NgZone.onStable
新名字好多了。