Swap .child and .stateNode in coroutines

It is slightly more useful this way because when we want to find host nodes
we typically want to do so in the second phase. That's the real tree where
as the first phase is more of a virtual part of the tree.
This commit is contained in:
Sebastian Markbage 2017-01-20 22:21:58 -08:00
parent 88b6175cb1
commit 648d6e190c
7 changed files with 60 additions and 17 deletions

View File

@ -518,11 +518,49 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
} else if (nextCoroutine === null || workInProgress.memoizedProps === nextCoroutine) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}
reconcileChildren(current, workInProgress, nextCoroutine.children);
const nextChildren = nextCoroutine.children;
const priorityLevel = workInProgress.pendingWorkPriority;
// The following is a fork of reconcileChildrenAtPriority but using
// stateNode to store the child.
// At this point any memoization is no longer valid since we'll have changed
// the children.
workInProgress.memoizedProps = null;
if (!current) {
workInProgress.stateNode = mountChildFibersInPlace(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);
} else if (current.child === workInProgress.child) {
clearDeletions(workInProgress);
workInProgress.stateNode = reconcileChildFibers(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);
transferDeletions(workInProgress);
} else {
workInProgress.stateNode = reconcileChildFibersInPlace(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);
transferDeletions(workInProgress);
}
memoizeProps(workInProgress, nextCoroutine);
// This doesn't take arbitrary time so we could synchronously just begin
// eagerly do the work of workInProgress.child as an optimization.
return workInProgress.child;
return workInProgress.stateNode;
}
function updatePortalComponent(current, workInProgress) {

View File

@ -136,7 +136,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
while (node.tag !== HostComponent && node.tag !== HostText) {
// If it is not host node and, we might have a host node inside it.
// Try to search down until we find one.
// TODO: For coroutines, this will have to search the stateNode.
if (node.effectTag & Placement) {
// If we don't have a child, try the siblings instead.
continue siblings;
@ -198,7 +197,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// down its children. Instead, we'll get insertions from each child in
// the portal directly.
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
@ -229,7 +227,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// Visit children because they may contain more composite or host nodes.
// Skip portals because commitUnmount() currently visits them recursively.
if (node.child && node.tag !== HostPortal) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
@ -273,7 +270,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
commitUnmount(node);
// Visit children because we may find more host components below.
if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;

View File

@ -66,6 +66,18 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
popHostContainer,
} = hostContext;
function markChildAsProgressed(current, workInProgress, priorityLevel) {
// We now have clones. Let's store them as the currently progressed work.
workInProgress.progressedChild = workInProgress.child;
workInProgress.progressedPriority = priorityLevel;
if (current) {
// We also store it on the current. When the alternate swaps in we can
// continue from this point.
current.progressedChild = workInProgress.progressedChild;
current.progressedPriority = workInProgress.progressedPriority;
}
}
function markUpdate(workInProgress : Fiber) {
// Tag the fiber with an update effect. This turns a Placement into
// an UpdateAndPlacement.
@ -73,7 +85,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
function appendAllYields(yields : Array<ReifiedYield>, workInProgress : Fiber) {
let node = workInProgress.child;
let node = workInProgress.stateNode;
while (node) {
if (node.tag === HostComponent || node.tag === HostText ||
node.tag === HostPortal) {
@ -81,7 +93,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
} else if (node.tag === YieldComponent) {
yields.push(node.type);
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
@ -123,16 +134,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
var props = coroutine.props;
var nextChildren = fn(props, yields);
var currentFirstChild = current ? current.stateNode : null;
var currentFirstChild = current ? current.child : null;
// Inherit the priority of the returnFiber.
const priority = workInProgress.pendingWorkPriority;
workInProgress.stateNode = reconcileChildFibers(
workInProgress.child = reconcileChildFibers(
workInProgress,
currentFirstChild,
nextChildren,
priority
);
return workInProgress.stateNode;
markChildAsProgressed(current, workInProgress, priority);
return workInProgress.child;
}
function appendAllChildren(parent : I, workInProgress : Fiber) {
@ -147,7 +159,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// down its children. Instead, we'll get insertions from each child in
// the portal directly.
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node = node.child;
continue;
}

View File

@ -435,6 +435,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
newPriority = getPendingPriority(queue);
}
// TODO: Coroutines need to visit stateNode
// progressedChild is going to be the child set with the highest priority.
// Either it is the same as child, or it just bailed out because it choose
// not to do the work.

View File

@ -168,7 +168,6 @@ exports.findCurrentHostFiber = function(parent : Fiber) : Fiber | null {
return node;
} else if (node.child) {
// TODO: If we hit a Portal, we're supposed to skip it.
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;

View File

@ -146,10 +146,8 @@ describe('ReactCoroutine', () => {
expect(ops).toEqual([
'Unmount Parent',
// TODO: This should happen in the order Child, Continuation which it
// will once we swap stateNode and child positions of these.
'Unmount Continuation',
'Unmount Child',
'Unmount Continuation',
]);
});

View File

@ -97,7 +97,6 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
}
}
if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;