@samitouri / QOS-React-2 / commits / b4b21486aa

Move all the begin work stuff into their own helper functions

This just moves things around to continue the pattern that we already started.

Sebastian Markbage committed Dec 20, 2016 at 21:36 UTC b4b21486aa043b3c6260665930e7e638c908a5ec
1 file changed +35 -34
src/renderers/shared/fiber/ReactFiberBeginWork.js
+35 -34
@@ -169,6 +169,7 @@ module.exports = function<T, P, I, TI, C, CX>(
169 function updateFragment(current, workInProgress) {
170 var nextChildren = workInProgress.pendingProps;
171 reconcileChildren(current, workInProgress, nextChildren);
172 + return workInProgress.child;
173 }
174
175 function updateFunctionalComponent(current, workInProgress) {
@@ -242,6 +243,30 @@ module.exports = function<T, P, I, TI, C, CX>(
243 return workInProgress.child;
244 }
245
246 + function updateHostRoot(current, workInProgress, priorityLevel) {
247 + const root = (workInProgress.stateNode : FiberRoot);
248 + if (root.pendingContext) {
249 + pushTopLevelContextObject(
250 + root.pendingContext,
251 + root.pendingContext !== root.context
252 + );
253 + } else {
254 + pushTopLevelContextObject(root.context, false);
255 + }
256 +
257 + pushHostContainer(root.containerInfo);
258 +
259 + const updateQueue = workInProgress.updateQueue;
260 + if (updateQueue) {
261 + const prevState = workInProgress.memoizedState;
262 + const state = beginUpdateQueue(workInProgress, updateQueue, null, prevState, null, priorityLevel);
263 + const element = state.element;
264 + reconcileChildren(current, workInProgress, element);
265 + workInProgress.memoizedState = state;
266 + }
267 + return workInProgress.child;
268 + }
269 +
270 function updateHostComponent(current, workInProgress) {
271 const nextProps = workInProgress.pendingProps;
272 const prevProps = current ? current.memoizedProps : null;
@@ -342,9 +367,13 @@ module.exports = function<T, P, I, TI, C, CX>(
367 throw new Error('Should be resolved by now');
368 }
369 reconcileChildren(current, workInProgress, coroutine.children);
370 + // This doesn't take arbitrary time so we could synchronously just begin
371 + // eagerly do the work of workInProgress.child as an optimization.
372 + return workInProgress.child;
373 }
374
375 function updatePortalComponent(current, workInProgress) {
376 + pushHostContainer(workInProgress.stateNode.containerInfo);
377 const priorityLevel = workInProgress.pendingWorkPriority;
378 const nextChildren = workInProgress.pendingProps;
379 if (!current) {
@@ -363,6 +392,7 @@ module.exports = function<T, P, I, TI, C, CX>(
392 } else {
393 reconcileChildren(current, workInProgress, nextChildren);
394 }
395 + return workInProgress.child;
396 }
397
398 /*
@@ -517,31 +547,8 @@ module.exports = function<T, P, I, TI, C, CX>(
547 return updateFunctionalComponent(current, workInProgress);
548 case ClassComponent:
549 return updateClassComponent(current, workInProgress, priorityLevel);
520 - case HostRoot: {
521 - const root = (workInProgress.stateNode : FiberRoot);
522 - if (root.pendingContext) {
523 - pushTopLevelContextObject(
524 - root.pendingContext,
525 - root.pendingContext !== root.context
526 - );
527 - } else {
528 - pushTopLevelContextObject(root.context, false);
529 - }
530 -
531 - pushHostContainer(root.containerInfo);
532 -
533 - if (updateQueue) {
534 - const prevState = workInProgress.memoizedState;
535 - const state = beginUpdateQueue(workInProgress, updateQueue, null, prevState, null, priorityLevel);
536 - const element = state.element;
537 - reconcileChildren(current, workInProgress, element);
538 - workInProgress.memoizedState = state;
539 - }
540 -
541 - // A yield component is just a placeholder, we can just run through the
542 - // next one immediately.
543 - return workInProgress.child;
544 - }
550 + case HostRoot:
551 + return updateHostRoot(current, workInProgress, priorityLevel);
552 case HostComponent:
553 return updateHostComponent(current, workInProgress);
554 case HostText:
@@ -553,21 +560,15 @@ module.exports = function<T, P, I, TI, C, CX>(
560 workInProgress.tag = CoroutineComponent;
561 // Intentionally fall through since this is now the same.
562 case CoroutineComponent:
556 - updateCoroutineComponent(current, workInProgress);
557 - // This doesn't take arbitrary time so we could synchronously just begin
558 - // eagerly do the work of workInProgress.child as an optimization.
559 - return workInProgress.child;
563 + return updateCoroutineComponent(current, workInProgress);
564 case YieldComponent:
565 // A yield component is just a placeholder, we can just run through the
566 // next one immediately.
567 return null;
568 case HostPortal:
565 - pushHostContainer(workInProgress.stateNode.containerInfo);
566 - updatePortalComponent(current, workInProgress);
567 - return workInProgress.child;
569 + return updatePortalComponent(current, workInProgress);
570 case Fragment:
569 - updateFragment(current, workInProgress);
570 - return workInProgress.child;
571 + return updateFragment(current, workInProgress);
572 default:
573 throw new Error('Unknown unit of work tag');
574 }