intendednull / yewdux

Ergonomic state management for Yew applications
https://intendednull.github.io/yewdux/
Apache License 2.0
319 stars 31 forks source link

Does the store get dropped when a component dismounts? #60

Open rollo-b2c2 opened 1 year ago

rollo-b2c2 commented 1 year ago

I was looking at the implementation of use store and I saw it used a threadlocal to do the global state.

If a component is dismounted, and it’s the only component using a certain store, does the store get dropped?

0x32c2cac3info commented 1 year ago

I believe the store persists beyond the period when the component is dropped for two reasons. The first reason is found here in the second paragraph, when it says: ...

_"For types that do not need to be dropped, this can enable an even more efficient implementation that does not need to track any additional state."

The other reason I think it persists is because "Static items do not call [drop](https://doc.rust-lang.org/reference/destructors.html) at the end of the program.", but this isn't necessarily the end of the program, right?

If it looks like you'd be worried about losing a store without proper saving or cleanup, there's always ManuallyDrop provided a fork of the repo implements it on a newtype wrapping the thread local, or something.

intendednull commented 11 months ago

This is correct, stores live for the entire application lifetime