Hi all, I have a question regarding best practices for subscriptions.
I have “mini” self-contained react components such as user look up, address look up, that relies on mongo collections and meteor subscriptions scattered around the app in various forms. Is it best to subscribe when the component gets mounted, or a global subscription based on user privileges when the app initialises or some the sub manager/caching mechanism?
Thanks,
Chat
I normally use two global publications that the user subscribes when he logs in: a userSettings
and a projectSettings
publication.
Both of these collections store almost-nothing and only publish one document, so the wait time for getting the documents is unnoticeable.
For all the other needs (for example, listing items) I subscribe whenever it is needed.
If you don’t like subscribing, clicking somewhere, then clicking again and having to re-download everything in the collection, you can use subs-manager to keep your subscription alive for a time period before destroying it.
When building realtime apps, you don’t want your users to wait on some long running processes, so rendering data as fast as you get it instead of waiting for a full sync is needed, most of the times. But remember to always show a little “loading” to let the users know what they see is not everything there is.