Skip to content

Instantly share code, notes, and snippets.

@pomber
Last active October 14, 2017 17:52
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 pomber/99468b62feebc9775147410092ad92ff to your computer and use it in GitHub Desktop.
Save pomber/99468b62feebc9775147410092ad92ff to your computer and use it in GitHub Desktop.
function cloneChildFibers(parentFiber) {
const oldFiber = parentFiber.alternate;
if (!oldFiber.child) {
return;
}
let oldChild = oldFiber.child;
let prevChild = null;
while (oldChild) {
const newChild = {
type: oldChild.type,
tag: oldChild.tag,
stateNode: oldChild.stateNode,
props: oldChild.props,
partialState: oldChild.partialState,
alternate: oldChild,
parent: parentFiber
};
if (prevChild) {
prevChild.sibling = newChild;
} else {
parentFiber.child = newChild;
}
prevChild = newChild;
oldChild = oldChild.sibling;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment