When do Subscriptions get unsubscribed


#1

Can you please let me know what happens to current template’s subscriptions when we navigate to another template in the same application. Does the miniMongo clear the data that was cached as part of previous template subscriptions


#2

You should read through the Meteor Guide on Publications - but this section should answer your question :smile:

Edit: Oops: wrong section link - corrected.


#3

Relevant bit here:

Stopping Subscriptions

The subscription handle also has another important property, the .stop() method. When you are subscribing, it is very important to ensure that you always call .stop() on the subscription when you are done with it. This ensures that the documents sent by the subscription are cleared from your local Minimongo cache and the server stops doing the work required to service your subscription. If you forget to call stop, you’ll consume unnecessary resources both on the client and the server.

However, if you call Meteor.subscribe() conditionally inside a reactive context (such as an autorun, or getMeteorData in React) or via this.subscribe() in a Blaze component, then Meteor’s reactive system will automatically call this.stop() for you at the appropriate time.

tl:dr; Meteor is the bee’s knees and will handle this for you. Don’t waste your time with trivialities and focus on product! :slight_smile:


#4

Yes I am subscribing in a reactive context and I want to retain the subscriptions across a set of pages before letting them go, so I wanted to control when the stop gets invoked. is that possible


#5

This might help: https://github.com/kadirahq/subs-manager


#6

Thanks. Yes I found this subscriptions manager earlier but now since you also recommend it, I feel more confident to go with it. Hopefully it works with 1.3 too because we have recently upgraded to 1.3 although struggling with hiccups like $(…).jstree isn’t a function (worked fine with 1.2). Found some help in the forums but they seem to be unreliable hacks, it will be great if you can provide guidance


#7

to import jstree you need to go into jstree.js and change the module to meteor/jquery

Otherwise you are subscribing to the wrong jquery object. I raised an issue with the repo owner earlier and will write up the solution so he can put it into his documentation