zodern / melte

Svelte compiler for Meteor with built in tracker integration and HMR
MIT License
33 stars 14 forks source link

How are subscriptions stopped? #14

Closed Prinzhorn closed 2 years ago

Prinzhorn commented 2 years ago

I'm probably just very confused right now. To track down some subscription issue I've narrowed it down to this:

<script>
  import { Meteor } from 'meteor/meteor';
  Meteor.subscribe('contacts');
</script>

If I render this component conditionally (toggling a checkbox) it will subscribe / unsubscribe from contacts. How? There is no $m or Tracker. I also can't see an onDestroy being generated for this component. What is this magic and how do I disable it? Does melte somehow globally wrap every component in a Tracker?

Edit: I need this because I want certain subscriptions to be subscribed to lazily (once needed) but then keep them open forever. I had this abstracted away and wondered why it was unsubscribing.

zodern commented 2 years ago

Is rdb:svelte-meteor-data in .meteor/versions? It modifies Meteor.subscribe to automatically unsubscribe when the component is destroyed.

Prinzhorn commented 2 years ago

Thank you very much, it is indeed! I was using the official Svelte skeleton and it includes both packages (https://github.com/meteor/meteor/blob/de41620db3ebd68e223fb1ae0a0eba9fd91cc700/tools/static-assets/skel-svelte/.meteor/packages).

I see value in both packages, but I like how unobtrusive this package is. I'll stick with it, thanks for creating it.