Day 4 React Virtual DOM

Day 4 React Virtual DOM

The purpose of computing is insight,not numbers————Richard Hamming(哈明码创造者)

React builds and maintains an internal representation of the rendered UI. It includes the React elements you return from your components.
React构建并维护“代表着已渲染的UI界面”的内部数据。这些内部数据包括了从组件返回的所有React元素。

This representation lets React avoid creating DOM nodes and accessing existing ones beyond necessity, as that can be slower than operations on JavaScript objects.
有了代表着UI界面的内部数据,React就可以在多数情况下避免去创建和访问DOM节点了,除非是到了十分必要的时候。因为操作“DOM对象”比操作“Javascript对象”要慢一些。

Sometimes it is referred to as a “virtual DOM”, but it works the same way on React Native.
这种内部数据有时候被称为“虚拟DOM节点”。但其实在React Native上它也以同样的方式工作着。

When a component’s props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM.
当一个组件的属性或状态改变时,React会比较组件新返回的元素和已经被渲染出来的元素是否一致,并以此决定是否需要更新DOM节点。只有当新返回的元素和已经被渲染的元素不一致时,React才会进行DOM更新。

Even though React only updates the changed DOM nodes, re-rendering still takes some time.
即便React只更新有改变的那些DOM节点,重新渲染依旧比较耗时。

In many cases it’s not a problem, but if the slowdown is noticeable, you can speed all of this up by overriding the lifecycle function shouldComponentUpdate, which is triggered before the re-rendering process starts.
在大多数情况下,这不是一个问题。但如果你注意到程序慢下来了,就可以通过重写shouldComponentUpdate这个生命周期函数来进行加速。shouldComponentUpdate会在每次重新渲染前被执行。

本文选自:
https://reactjs.org/docs/optimizing-performance.html

生词 音标 释义
maintain [meɪnˈteɪn] vt. 维护
internal representation 内部表现,内部映射
rendered ['rendəd] adj. 渲染过的
UI 全称:User Interface,用户界面
beyond [bɪˈjɑ:nd] prep. 超过
necessity [nəˈsɛsɪti] n. 必需品;必要性
component [kəmˈpoʊnənt] n. 组成;成分
access [ək'sɛs] n. 接近;进入
refer to 参考;指的是
virtual [ˈvɜ:rtʃuəl] adj. 虚拟的
prop [prɑ:p] n. 特征
state [stet] n. 状态
newly [ˈnu:li] adv. 新近
previously [ˈprivɪəslɪ] adv. 以前
even though 哪怕;即使
in many cases 在多数情况下
slowdown [ˈsloʊdaʊn] n. 减速
noticeable [ˈnoʊtɪsəbl] adj. 明显的
override [oʊvərˈraɪd] v. 覆盖,重写
lifecycle function 生命周期函数
trigger [ˈtrɪɡɚ] v. 触发
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 前些天和朋友见面,看到他还是过去那副老样子,我就问他:“你半年前不是嚷嚷着要坚持锻炼身体,还到健身房办了年卡吗,怎...
    d730c4d1398b阅读 1,634评论 0 0
  • 近些日子,眼看街边小推车上的菠萝堆成小山,菠萝的香气吸引着人群不自觉的往小车聚拢。卖菠萝人站在车后熟练操着小刀,菠...
    西先生和贝小姐阅读 3,926评论 0 0
  • 温清璇望着转身而去的王钟等人,然后笑吟吟的看向牧尘,道:“看来你又多了一个对头...抱歉啊,我给你惹麻烦了。” 虽...
    混沌天书阅读 3,064评论 0 0
  • 风拂过 摇摆出轻盈曼妙的舞姿 叮咚出清脆悦耳的音韵 舞姿美 音韵幽美 风儿止 串连着错落唯美的图案 沉静着窈窕修长...
    随缘wang阅读 2,662评论 3 3

友情链接更多精彩内容