Don't track side-effects unless needed

We don't need to track side-effects for a parent that has never
been mounted before. It will simply inject all its children when
it completes.
This commit is contained in:
Sebastian Markbage 2016-09-20 18:12:20 -07:00 committed by Sebastian Markbåge
parent cccc4ae2c6
commit 3979bb9e24
1 changed files with 49 additions and 51 deletions

View File

@ -56,35 +56,40 @@ const {
NoWork, NoWork,
} = ReactPriorityLevel; } = ReactPriorityLevel;
// This wrapper function exists because I expect to clone the code in each path
// to be able to optimize each path individually by branching early. This needs
// a compiler or we can do it manually. Helpers that don't need this branching
// live outside of this function.
function ChildReconciler(shouldClone, shouldTrackSideEffects) {
function deleteChild( function deleteChild(
returnFiber : Fiber, returnFiber : Fiber,
childToDelete : Fiber childToDelete : Fiber
) { ) {
if (!shouldTrackSideEffects) { if (!shouldTrackSideEffects) {
// Noop. // Noop.
return; return;
} }
// TODO: Add this child to the side-effect queue for deletion. // TODO: Add this child to the side-effect queue for deletion.
} }
function deleteRemainingChildren( function deleteRemainingChildren(
returnFiber : Fiber, returnFiber : Fiber,
currentFirstChild : ?Fiber currentFirstChild : ?Fiber
) { ) {
if (!shouldTrackSideEffects) { if (!shouldTrackSideEffects) {
// Noop. // Noop.
return null; return null;
} }
// TODO: Add these children to the side-effect queue for deletion. // TODO: Add these children to the side-effect queue for deletion.
return null; return null;
} }
function mapAndDeleteRemainingChildren( function mapAndDeleteRemainingChildren(
returnFiber : Fiber, returnFiber : Fiber,
currentFirstChild : ?Fiber currentFirstChild : ?Fiber
) : Map<string, Fiber> { ) : Map<string, Fiber> {
// Add the remaining children to a temporary map so that we can find them by // Add the remaining children to a temporary map so that we can find them by
// keys quickly. At the same time, we'll flag them all for deletion. However, // keys quickly. At the same time, we'll flag them all for deletion. However,
// we will then undo the deletion as we restore children. Implicit (null) keys // we will then undo the deletion as we restore children. Implicit (null) keys
@ -104,14 +109,7 @@ function mapAndDeleteRemainingChildren(
existingChild = existingChild.sibling; existingChild = existingChild.sibling;
} }
return existingChildren; return existingChildren;
} }
// This wrapper function exists because I expect to clone the code in each path
// to be able to optimize each path individually by branching early. This needs
// a compiler or we can do it manually. Helpers that don't need this branching
// live outside of this function.
function ChildReconciler(shouldClone, shouldTrackSideEffects) {
function useFiber(fiber : Fiber, priority : PriorityLevel) { function useFiber(fiber : Fiber, priority : PriorityLevel) {
// We currently set sibling to null and index to 0 here because it is easy // We currently set sibling to null and index to 0 here because it is easy