Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit deletion #22

Open
lxsmnsyc opened this issue Feb 13, 2020 · 4 comments
Open

commit deletion #22

lxsmnsyc opened this issue Feb 13, 2020 · 4 comments

Comments

@lxsmnsyc
Copy link

lxsmnsyc commented Feb 13, 2020

Hello, I saw this repo for reverse-engineering or creating your own React library. It was a great project, but I have a question.

In this specific line:
https://github.com/pomber/didact/blob/master/didact.js#L136

function commitDeletion(fiber, domParent) {
  if (fiber.dom) {
    domParent.removeChild(fiber.dom)
  } else {
    commitDeletion(fiber.child, domParent)
  }
}

How does commitDeletion perform on sibling fibers of the given child fiber?

@pomber
Copy link
Owner

pomber commented Feb 13, 2020

Good question. The trick is: if fiber.dom is null it means it's the fiber of a function component, and function components never have more than one child (Didact doesn't have Fragments like React).

@lxsmnsyc
Copy link
Author

Oh, I didn't notice it was implemented that way, thanks for the reply!

I'm curious, how would you implement it if it can accept multiple children?

@pomber
Copy link
Owner

pomber commented Feb 15, 2020

It's more complex because you need to search the different dom nodes that may be at different levels on the subtrees.
See here: https://gist.github.com/pomber/64fb7e63119bef201dd8166b0fce73c4#file-didact-fiber-js-L30 (from https://engineering.hexacta.com/didact-fiber-incremental-reconciliation-b2fe028dcaec)

@lxsmnsyc
Copy link
Author

I see, thanks! I had a different implementation by iterating each children and then doing the recursive call to commitDeletion: https://github.com/LXSMNSYC/luact/blob/master/luact/fiber/commit_delete/init.lua

Anyways, big thanks to this DIY React project of yours, I get to learn about React Fiber's internal workings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants