Raynos / mercury

A truly modular frontend framework
http://raynos.github.io/mercury/
MIT License
2.82k stars 143 forks source link

question: how to detect if a widget has been unmounted #188

Open yoshuawuyts opened 9 years ago

yoshuawuyts commented 9 years ago

When building a widget only init and update hooks are exposed. How do I know when a Node is destroyed so I can clean up elements?

I can check if a node is removed by doing in update if (prev.parentNode === null), but that feels somewhat dirty. I was wondering if there's a better way (e.g. using hooks perhaps?) Thanks!

edit: I'm not even sure if update() is called once an element has been unmounted, thus rendering the check moot. A pointer in the right direction would be much appreciated.

crabmusket commented 9 years ago

Does this help? Apparently there should be a destroy method.

yoshuawuyts commented 9 years ago

Ah, yes that is exactly what I was looking for. It wasn't showing up in the other docs. I'll update my https://github.com/yoshuawuyts/virtual-widget package to include this method. Thanks! :tada: