Angular:它是否与 ReactJS 的 "Reconciliation" 等效?
Angular: does it have an equivalent to ReactJS's "Reconciliation"?
在阅读了关于 ReactJS 和 Angular(不是 AngularJS)变化检测和渲染阶段的文档和几篇文章后,我想到了一个我会尝试的问题稍后解释。
正如你可能在 React 的文档 (here and here) 中读到的那样,存在这个概念(如果你愿意的话)叫做“Reconciliation”,它基本上指的是“ Diffing Algorithm”和调用“render”方法后执行的过程,创建 React 元素树,DOM 应该相应更新...正如他们的文档中所说,React 实现了启发式 O(n) 算法,该算法比较新版本的 virtual DOM ( VDOM) 与前一个,以便有效地只更新那些真正改变的视图部分。
但是谈论 Angular,正如我在 here, here and here 等文章中读到的那样,另一方面 Angular 似乎只看“bindings" 它从模板派生:
When the compiler analyzes the template, it identifies properties of a
component that are associated with DOM elements. For each such
association, the compiler creates a binding in the form of
instructions. A binding is the core part of change detection in
Angular.
然后:
Once bindings are created, Angular no longer works with the template.
The change detection mechanism executes instructions that process
bindings. The job of these instructions is to check if the value of an
expression with a component property has changed and perform DOM
updates if necessary.
总结一下:
Processing bindings that perform dirty checks and update the relevant
parts of the DOM are the core operations of change detection in
Angular.
(从第三个开始link)
所以我的问题是,当 Angular 在“bindings”而不是整个新生成的 template/VDOM 从而消除了对优化差异算法的需要?
或者在 Angular 的变更检测中是否还有其他一些实现这种效率的点?
can we say that Angular achieves a similar performance boost... thus
eliminating the need for an optimized diffing algorithm
是
React 中实际上没有进行太多优化。它只是比较 returned child 元素的类型并丢弃树。与钥匙的比较更加复杂。我会说 Angular 运行变更检测更快,因为所有 children 在编译时都是已知的,但 React 更灵活,因为你可以 return 一个全新的 child每一次。在 Angular 中,您需要了解一大堆概念才能动态更改或删除 children。在 React 中,这只是 return 与 render
方法不同的 child 的问题。
在阅读了关于 ReactJS 和 Angular(不是 AngularJS)变化检测和渲染阶段的文档和几篇文章后,我想到了一个我会尝试的问题稍后解释。
正如你可能在 React 的文档 (here and here) 中读到的那样,存在这个概念(如果你愿意的话)叫做“Reconciliation”,它基本上指的是“ Diffing Algorithm”和调用“render”方法后执行的过程,创建 React 元素树,DOM 应该相应更新...正如他们的文档中所说,React 实现了启发式 O(n) 算法,该算法比较新版本的 virtual DOM ( VDOM) 与前一个,以便有效地只更新那些真正改变的视图部分。
但是谈论 Angular,正如我在 here, here and here 等文章中读到的那样,另一方面 Angular 似乎只看“bindings" 它从模板派生:
When the compiler analyzes the template, it identifies properties of a component that are associated with DOM elements. For each such association, the compiler creates a binding in the form of instructions. A binding is the core part of change detection in Angular.
然后:
Once bindings are created, Angular no longer works with the template. The change detection mechanism executes instructions that process bindings. The job of these instructions is to check if the value of an expression with a component property has changed and perform DOM updates if necessary.
总结一下:
Processing bindings that perform dirty checks and update the relevant parts of the DOM are the core operations of change detection in Angular.
(从第三个开始link)
所以我的问题是,当 Angular 在“bindings”而不是整个新生成的 template/VDOM 从而消除了对优化差异算法的需要?
或者在 Angular 的变更检测中是否还有其他一些实现这种效率的点?
can we say that Angular achieves a similar performance boost... thus eliminating the need for an optimized diffing algorithm
是
React 中实际上没有进行太多优化。它只是比较 returned child 元素的类型并丢弃树。与钥匙的比较更加复杂。我会说 Angular 运行变更检测更快,因为所有 children 在编译时都是已知的,但 React 更灵活,因为你可以 return 一个全新的 child每一次。在 Angular 中,您需要了解一大堆概念才能动态更改或删除 children。在 React 中,这只是 return 与 render
方法不同的 child 的问题。