flamethrower icon indicating copy to clipboard operation
flamethrower copied to clipboard

option to preserve nodes when replacing the body.

Open prowebat opened this issue 2 years ago • 3 comments

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>

prowebat avatar Aug 20 '22 13:08 prowebat

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.

ekwoka avatar Aug 23 '22 18:08 ekwoka

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.

prowebat avatar Aug 23 '22 19:08 prowebat

This looks cool! Going to test it out.

codediodeio avatar Aug 26 '22 04:08 codediodeio