请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,对于 Fiber 的 UpdateQuene 在不同阶段数据结构的变化有疑问

Fiber 的 updateQuene 在定义结构是时候是一个对象,包含 firstUpdate、firstEffect 等等属性。 在调用 enquneUpdateQuene 的时候使用的是这个结构,但是在 completeWork 阶段执行 updateHostComponent 的时候 Fiber.updateQuene 就变成了一个数组,其中每两项分别是一个 key 和 value,这两种情况下数据结构改变了,不知道我理解的是否正确,如果正确这样做的目的是什么,为什么不用同一个数据结构

UpdateQueue 的数据结构是这样的


type UpdateQueue<State> = {

baseState: State,



firstUpdate: Update<State> | null,

lastUpdate: Update<State> | null,



firstCapturedUpdate: Update<State> | null,

lastCapturedUpdate: Update<State> | null,



firstEffect: Update<State> | null,

lastEffect: Update<State> | null,



firstCapturedEffect: Update<State> | null,

lastCapturedEffect: Update<State> | null,

};

在 completeWork 阶段执行 updateHostComponent 的时候 代码位置react/packages/react-reconciler/src/ReactFiberCompleteWork.js/updateHostComponent


const updatePayload = prepareUpdate(

instance,

type,

oldProps,

newProps,

rootContainerInstance,

currentHostContext,

);

// TODO: Type this specific to this type of component.

workInProgress.updateQueue = updatePayload;

prepareUpdate 执行完之后返回的是一个数组,会赋值给 workInProgress.updateQueue 这与上面定义的数据结构中 UpdateQueue 的数据结构是不同的

正在回答 回答被采纳积分+3

1回答

Jokcy 2020-02-24 19:02:36

说实话你现在问我这么细节的问题,我是回答不上来了,如果确实数据结构变了,建议你看后续updateQueue在什么地方用到了,是不是因为后续的使用所以变动。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号