-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect Stores to Element connected/disconnected lifecycle #111
Comments
Hmm ... not sure about that ? As long as the last element referencing the store will be removed from the document at some point there will be no hard reference to the store which would allow GC to clean up at some point? And if its a singleton than it wight as well persist, right ? Also we might want to move this to discussions, shall we ? |
It is not about the store itself. I thought about other things you do/register from the store. import { Store } from '@webtides/element-js';
export default class MatchMediaStore extends Store {
_mediaQueryList;
matches;
_onMatchMedia = (e) => {
this.matches = e.matches;
this.requestUpdate();
};
constructor(mediaQueryString) {
super();
this._mediaQueryList = window.matchMedia(mediaQueryString);
this.matches = this._mediaQueryList.matches;
this.requestUpdate();
this._mediaQueryList.addEventListener('change', this._onMatchMedia);
}
} It is porbably not the worst, but there is currently no way to remove added event listeners again. I have seen something alike for lit: |
Understood .. but since the store is not referenced anywhere i assume the internals will get cleaned up eventually. As for the client/server part ... there is always the possibility to expose a dedicated on/off/pause function that could be used by elements only clientside || serverside. I don't like the idea too much of coupling them Store and Element even more (although they are already for the autoUpdate). Also its quite hard to decide when a (singleton or shared) store becomes void as it might be referenced during runtime. The only Option i can think of is to maybe proxy the observers list and destroy whenever that becomes empty !? But that also sounds like we'll introduce quite a few runtime issues ... |
Currently the only way to init things in Stores is the constructor. But it is unsafe to use browser globals in there. And also there is no chance to eg remove document listeners.
The text was updated successfully, but these errors were encountered: