snabbdom / snabbdom

A virtual DOM library with focus on simplicity, modularity, powerful features and performance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is these repo supports reuse vnode and dom element in different containers.

ruojianll opened this issue · comments

I'm working on building a low code platform to build web pages. So we need to drag a component(a wrapped dom element) from an old container to a new container. The component should be reused to prevent destroy and rebuild it. In another word, move a vnode to a new parent vnode and reuse the element. It this repo supports that feature?

I'm not an expert snabbdom user but, I believe the answer is "yes"

After the element is dragged to the new location, rebuild the root vnode from the document and/or update your application state to patch-apply the element to the new container.

If you want the DOM element in the new container to be the same DOM element as in the old container, then this can be done but is not trivial.

A sketch of a solution would be to create a custom module, use the destroy hook to add the old element to a map along with some unique id for it, and use the init hook to find the old element in the map. While different the hero module does something a bit along those lines.

Feel free to ask more questions (but I assume that this is no longer relevant to you given the time since the question).