Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React:fiber #51

Open
HCLacids opened this issue Mar 1, 2022 · 0 comments
Open

React:fiber #51

HCLacids opened this issue Mar 1, 2022 · 0 comments
Labels

Comments

@HCLacids
Copy link
Owner

HCLacids commented Mar 1, 2022

参考链接
fiber确实就是一个数据结构,一种树,他表示着所有的节点之间的关系。
工作机制:
首先requestIdleCallback函数调用一个workLoop,requestIdleCallback会在浏览器空闲时自己调用,而浏览器控制时,启动下一个requestIdleCallback在再次在浏览器控制时调用。
在调用render函数的时候,首先会将一个fiber的树根结构wipRoot初始化,nextUnitOfWork赋值为wipRoot。开始一个工作loop时候,以wipRoot的根节点为主,找到节点之间的关系,并创建dom。
一个fiber的结构为

type: element.type,
props: element.props,
parent: wipFiber,
dom: null,
alternate: null,
effectTag: "PLACEMENT"

确定完关系后,再提交当前的结果,利用parent等指针来将dom形成dom tree
再次将这次的fiber tree保存下来,用于下次渲染的节点比对。
遍历一个fiber tree的顺序是,根节点,找子节点,再找兄弟节点递归遍历,找完所有兄弟节点后,返回父节点。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant