Skip to content

Instantly share code, notes, and snippets.

@Tevinthuku
Last active August 14, 2019 13:45
Show Gist options
  • Save Tevinthuku/bfbab503951f708e869ac7f653196d3e to your computer and use it in GitHub Desktop.
Save Tevinthuku/bfbab503951f708e869ac7f653196d3e to your computer and use it in GitHub Desktop.
// ...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