加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular2理解VM转向和事件

发布时间:2020-12-17 17:54:22 所属栏目:安全 来源:网络整理
导读:我刚刚开始进入Angular2变化检测机制. 我已经阅读了关于这个主题的那篇文章(ZoneJS和Angular2区域的文章),但仍然有一个术语我找不到任何定义. 这是this帖子的摘录: NgZone is basically a forked zone that extends its API and adds some additional funct
我刚刚开始进入Angular2变化检测机制.

我已经阅读了关于这个主题的那篇文章(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.

解决方法

如果有人对答案感兴趣,这对我来说很清楚: https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/

当然,还阅读了Dylan Meeus给我的链接:What are zone turns?

这就是我现在所理解的这些术语的含义:

VM turn =浏览器任务 – 由堆栈清除时运行的某些浏览器事件循环(例如setTimout队列)处理的回调.

VM事件 – 浏览器处理所有待处理任务的操作.

Microtask – 正如上面链接的帖子中所描述的那样,这些回调是根据HTML规范,不应该出于性能原因(例如承诺和观察者)被安排为任务,因此它们被安排为称为微任务的东西.
微任务进入其自己的特殊队列,该队列在每个回调或任务结束时运行,这意味着如果任务调度微任务,则该微任务将在该任务结束时运行,阻止当时在队列中等待的任何任务.

我希望这可以帮助别人 :)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读