Change Detection 过程以及检查 OnPush 属性的确切时间
Change Detection process and which exact time check OnPush properties
在https://hackernoon.com/everything-you-need-to-know-about-change-detection-in-angular-8006c51d206f
他说 angular 有 14 个操作,但是它检查组件是否为 ChecksEnabled == false (OnPush) 的确切时刻,特别是如果它是 OnPush 时它检查某些 @Input 属性已更改为运行里面的进程呢?并继续检查 DOM 并调用所需的生命周期?
如果该值是一个新引用,它会 运行 只检查 @Input 的那个值的属性,或者根本不检查绑定?同意我的看法,如果他只检查该元素的值绑定,性能会更好吗?
At which exact moment it's checked if the component is ChecksEnabled
== false (OnPush)
当 Angular 运行子视图检查时发生:
- 为子视图运行更改检测(重复此列表中的步骤)
相关代码如下:
function callViewAction(view: ViewData, action: ViewAction) {
const viewState = view.state;
switch (action) {
...
case ViewAction.CheckAndUpdate:
if ((viewState & ViewState.Destroyed) === 0) {
if ((viewState & ViewState.CatDetectChanges) === ViewState.CatDetectChanges) {
checkAndUpdateView(view);
} else if (viewState & ViewState.CheckProjectedViews) {
execProjectedViewsAction(view, ViewAction.CheckAndUpdateProjectedViews);
}
}
break;
At what time it checks some @Input properties has changed to run the
process inside it
这是为这一步执行的:
- 更新子 component/directive 实例的输入属性
要了解更多信息,请阅读 The mechanics of property bindings update in Angular
And continue with the check in the DOM and invoke the required life
cycles ?
这将在:
- 如果当前视图组件实例的属性发生变化,则更新DOM 当前视图的插值和绑定
要了解更多信息,请阅读 The mechanics of DOM updates in Angular
在https://hackernoon.com/everything-you-need-to-know-about-change-detection-in-angular-8006c51d206f
他说 angular 有 14 个操作,但是它检查组件是否为 ChecksEnabled == false (OnPush) 的确切时刻,特别是如果它是 OnPush 时它检查某些 @Input 属性已更改为运行里面的进程呢?并继续检查 DOM 并调用所需的生命周期?
如果该值是一个新引用,它会 运行 只检查 @Input 的那个值的属性,或者根本不检查绑定?同意我的看法,如果他只检查该元素的值绑定,性能会更好吗?
At which exact moment it's checked if the component is ChecksEnabled == false (OnPush)
当 Angular 运行子视图检查时发生:
- 为子视图运行更改检测(重复此列表中的步骤)
相关代码如下:
function callViewAction(view: ViewData, action: ViewAction) {
const viewState = view.state;
switch (action) {
...
case ViewAction.CheckAndUpdate:
if ((viewState & ViewState.Destroyed) === 0) {
if ((viewState & ViewState.CatDetectChanges) === ViewState.CatDetectChanges) {
checkAndUpdateView(view);
} else if (viewState & ViewState.CheckProjectedViews) {
execProjectedViewsAction(view, ViewAction.CheckAndUpdateProjectedViews);
}
}
break;
At what time it checks some @Input properties has changed to run the process inside it
这是为这一步执行的:
- 更新子 component/directive 实例的输入属性
要了解更多信息,请阅读 The mechanics of property bindings update in Angular
And continue with the check in the DOM and invoke the required life cycles ?
这将在:
- 如果当前视图组件实例的属性发生变化,则更新DOM 当前视图的插值和绑定
要了解更多信息,请阅读 The mechanics of DOM updates in Angular