-
Notifications
You must be signed in to change notification settings - Fork 1
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
Explanation of subtree patching algorithm #1
Comments
Hi @jayrbolton, I'm very glad to know about your interest in the snabbmitt code. Right now I'm busy traveling to home but tomorrow I can write you a better description of how it works. |
So, the idea started when I tested the /**
* lastVtree is the last version of our entire virtual dom patched in the DOM
* so each vnode has their `elm` property set
*
**/
// we can do this
const subtree = lastVtree.children[0];
patch(subtree, newVnode); Since every element in the vtree is a regular vnode, it's understandable that the When I had this part finished I started with the stateful component part. In snabbmitt, a stateful component is a closure function where you can define a view and a store. I don't know if this description clarifies your questions or tell me if you need help for a specific part. |
Many thanks @tinchoz49 , this explanation is helpful for me to understand better. I'll be playing with the code! |
new ideas are welcome too! 😄 |
Hi @tinchoz49, I'm returning to this after a very long delay ... I still like the idea here a lot. One question I have is how you can aggregate data from child components. For example, in your You would need to access the state of each child from the parent on every child update, add them together, and display that within the parent. Maybe you've thought about or played with this use case? I think in real-world apps this type of aggregation is very common. |
So I was thinking of adding a global bus that could solve the above issue. With a global bus, you could access any arbitrary state and trigger arbitrary events from one component to another without having to worry about parameters. When you initialize a component, you could set its namespace for the global bus. From any other component, you could listen to and fire events to any other component if you have its namespace. I'm going to play with idea (in a very large and complex app) and see if it works well. |
Hey @tinchoz49, I'm interested in your code here and am trying to grok how your subtree patching works. Would you be willing to describe a little bit how it works?
The text was updated successfully, but these errors were encountered: