Open dailynodejs opened 3 years ago
function createFiberFromElement(element, mode, expirationTime) {
var owner = null;
{
owner = element._owner;
}
var type = element.type;
var key = element.key;
var pendingProps = element.props;
var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
{
fiber._debugSource = element._source;
fiber._debugOwner = element._owner;
}
return fiber;
}
var Fragment = 7;
function createFiberFromFragment(elements, mode, expirationTime, key) {
var fiber = createFiber(Fragment, elements, key, mode);
fiber.expirationTime = expirationTime;
return fiber;
}
var HostText = 6;
function createFiberFromText(content, mode, expirationTime) {
var fiber = createFiber(HostText, content, null, mode);
fiber.expirationTime = expirationTime;
return fiber;
}
var shouldIgnoreFiber = function (fiber) {
// Host components should be skipped in the timeline.
// We could check typeof fiber.type, but does this work with RN?
switch (fiber.tag) {
case HostRoot:
case HostComponent:
case HostText:
case HostPortal:
case Fragment:
case ContextProvider:
case ContextConsumer:
case Mode:
return true;
default:
return false;
}
};
function setCurrentFiber(fiber) {
{
ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
current = fiber;
phase = null;
}
}
function useFiber(fiber, pendingProps, expirationTime) {
// We currently set sibling to null and index to 0 here because it is easy
// to forget to do before returning it. E.g. for the single child case.
var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
clone.index = 0;
clone.sibling = null;
return clone;
}
https://blog.csdn.net/weixin_34167819/article/details/91423183
对象,包含
key | type | desc |
---|---|---|
current | (HostRoot)FiberNode | 指向当前已经完成的Fiber Tree 的Root |
containerInfo | DOMContainer | React的DOM容器,把整个React渲染到这个DOM内部 |
finishedWork | (HostRoot)FiberNode|null | 指向当前已经完成准备工作的Fiber Tree Root |
视频参考:https://www.youtube.com/watch?v=ZCuYPiUIONs&list=PLb0IAmt7-GS3fZ46IGFirdqKTIxlws7e0&index=6 文章参考:https://juejin.cn/post/6943896410987659277
在 react16 引入 Fiber 架构之前,react 会采用递归对比虚拟DOM树,找出需要变动的节点,然后同步更新它们,这个过程 react 称为reconcilation(协调)。在reconcilation期间,react 会一直占用浏览器资源,会导致用户触发的事件得不到响应。实现的原理如下所示:
16 中的协调引擎,使 Virtual DOM 进行增量式渲染
What?
一个执行单元,一种数据结构
FiberNode