flamethrower
flamethrower copied to clipboard
option to preserve nodes when replacing the body.
this pull request avoids that web components are recreated on each page navigation.
how: nodes with the attribute "flamethrower-preserve" will be moved to the new page body instead of recreating them. (id has to be unique and match on the old and new page)
example with an "app-drawer" web component:
<app-drawer id="preserve-drawer" flamethrower-preserve>content</app-drawer>
This does seem like a decent method.
Protip though, there is a replaceChildren
method so you don't need to remove the children one by one (and of course append accepts multiple nodes at once)
Can probably just use #${id}
instead of the id attribute selector as well.
oh yes, replaceChildren might also work.
in my experience the selector [id="..."] is more robust than #${id}. eg. there might be special characters like "[]." in it.
This looks cool! Going to test it out.