The best example for organizing my subscribers in Meteor is not ready to find data without risk

I read some of the posts here on how to organize subscriptions in Meteorjs, but I still don’t understand which template is the best, so as not to find some of the data that I signed up, not ready for use in the template. I use Iron Router and now I have all my subscriptions organized using the waitOn option in Router.configure. I find out that this method sometimes does not help. If I have several signatures like this:

Router.configure({
    layoutTemplate: 'layout',
    loadingTemplate: 'loading',
    waitOn: function () {
        return [
            Meteor.subscribe('channels'),
            Meteor.subscribe('invitations'),
            Meteor.subscribe('messages')
        ];
    } 
});

I realized that order matters. If I change the order of my subscriptions in an array, the program will respond differently. I want to get ALL my subscriptions fully loaded before navigating the application. Someone in a previous post talked about putting them in a separate file in order to solve this problem. But how? Where do I need to put this file? I would appreciate some examples for my case.

+4
source share
1 answer

With the release Meteor 1.0.4, template instances now have a subscription method that works exactly the same way Meteor.subscribe, check this version to learn more about

So, you can use these subscriptions inside onCreated, as in the following example.

Template.notifications.onCreated(function () {
  this.subscribe("channels");
  this.subscribe("invitations");
  this.subscribe("messages");
});

subscriptionsReady()

+6

All Articles