I'm messing around with a generic way to do hot-module-replacement with generic web components whether they be vanilla, or done in a framework like Polymer or Skate.
The idea is that you call hmr(customElementConstructor)
in your module files and it will set up the proper hooks.
The const filename
should be inserted at build time so that it can remember the original localName
of the component for the module.
filename
represents the filename at build time. This should be replaced with that.x-layout
just a dummy filename I was using for testing.Layout
a constructor that I was testing.
When you replace the node, you have to reconstruct it as it was before. If the original node was being interacted with, you'd lose UX state, even if it was restored back to its original internal state.
No reason yet. It doesn't appear, at this point, that it would make a difference at all since all replacements need to happen at some point.
very nice, thank you @treshugart