Last active
August 14, 2019 13:45
-
-
Save Tevinthuku/bfbab503951f708e869ac7f653196d3e 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
// ...code | |
let pendingCommit = null; // this is what will be flushed to the dom | |
// ... code | |
function completeWork(fiber) { | |
// this function takes the list of effects of the children and appends them to the effects of | |
// the parent | |
if (fiber.tag == CLASS_COMPONENT) { | |
// update the stateNode.__fiber of the | |
// class component to the new wipFiber (it doesn't deserve this name anymore since we are done with the work we needed to do to it) | |
fiber.stateNode.__fiber = fiber; | |
} | |
if (fiber.parent) { | |
// append the fiber's child effects to the parent of the fiber | |
// the effects of the childFiber | |
// are appended to the fiber.effects | |
const childEffects = fiber.effects || []; | |
// if the effectTag is not present of this fiber, if there are none, | |
// then return an empty list | |
const thisEffect = fiber.effectTag != null ? [fiber] : []; | |
const parentEffects = fiber.parent.effects || []; | |
// the new parent effects consists of this current fiber's effects + | |
// effects of this current Fiber + the parent's own effects | |
fiber.parent.effects = parentEffects.concat(childEffects, thisEffect); | |
} else { | |
// if the fiber does not have a parent then it means we | |
// are at the root. and ready to flush the changes to the dom. | |
pendingCommit = fiber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment