Skip to content

Instantly share code, notes, and snippets.

@Tevinthuku
Created August 14, 2019 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tevinthuku/69d57093eb61746d2b85c26388a9880f to your computer and use it in GitHub Desktop.
Save Tevinthuku/69d57093eb61746d2b85c26388a9880f to your computer and use it in GitHub Desktop.
performunitofwork
// ... code
function performUnitOfWork(wipFiber) {
// lets work on the fiber
beginWork(wipFiber);
if (wipFiber.child) {
// if a child exists its passed on as
// the nextUnitOfWork
return wipFiber.child;
}
// No child, we call completeWork until we find a sibling
let uow = wipFiber;
while (uow) {
completeWork(uow); // completework on the currentFiber
// return the siblings of the currentFiber to
// be the nextUnitOfWork
if (uow.sibling) {
// Sibling needs to beginWork
return uow.sibling;
}
// if no siblings are present,
// lets climb up the tree as we call completeWork
// when no parent is found / if we've reached the top,
// this function returns null and thats how we know that we have completed
// working on the work in progress tree.
uow = uow.parent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment