Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

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

Open
yoshuawuyts opened this issue Oct 4, 2015 · 2 comments
Open

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

yoshuawuyts opened this issue Oct 4, 2015 · 2 comments

Comments

@yoshuawuyts
Copy link

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.

@yoshuawuyts yoshuawuyts changed the title question: how to clean up unmount hooks for widgets question: how to detect if a widget has been unmounted Oct 4, 2015
@crabmusket
Copy link
Contributor

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

@yoshuawuyts
Copy link
Author

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! 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants