Hacker News new | ask | show | jobs
by peanut_worm 1798 days ago
What does storing the state as a WeakMap do here?
2 comments

I initially just mimicked the React version into Vanilla, so this was a show-off how to do that somewhat exactly the same way. But in this particular case it serves no meaning, we can always read 'checked' from DOM.
If the custom DOM element is deleted, then its entry in the map will also be deleted. Otherwise it would hang around in the Map forever (unless manually deleted in a lifecycle callback).
Why would component's state sit outside the component anyway? Why isn't it a field on the extended class?
True, it would make more sense to do that.