Last active
February 15, 2020 04:18
-
-
Save pomber/64fb7e63119bef201dd8166b0fce73c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function commitAllWork(fiber) { | |
fiber.effects.forEach(f => { | |
commitWork(f); | |
}); | |
fiber.stateNode._rootContainerFiber = fiber; | |
nextUnitOfWork = null; | |
pendingCommit = null; | |
} | |
function commitWork(fiber) { | |
if (fiber.tag == HOST_ROOT) { | |
return; | |
} | |
let domParentFiber = fiber.parent; | |
while (domParentFiber.tag == CLASS_COMPONENT) { | |
domParentFiber = domParentFiber.parent; | |
} | |
const domParent = domParentFiber.stateNode; | |
if (fiber.effectTag == PLACEMENT && fiber.tag == HOST_COMPONENT) { | |
domParent.appendChild(fiber.stateNode); | |
} else if (fiber.effectTag == UPDATE) { | |
updateDomProperties(fiber.stateNode, fiber.alternate.props, fiber.props); | |
} else if (fiber.effectTag == DELETION) { | |
commitDeletion(fiber, domParent); | |
} | |
} | |
function commitDeletion(fiber, domParent) { | |
let node = fiber; | |
while (true) { | |
if (node.tag == CLASS_COMPONENT) { | |
node = node.child; | |
continue; | |
} | |
domParent.removeChild(node.stateNode); | |
while (node != fiber && !node.sibling) { | |
node = node.parent; | |
} | |
if (node == fiber) { | |
return; | |
} | |
node = node.sibling; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment