Question

I'm in a situation where I need to have the full data from several subscriptions before my app can run properly. In a jQuery/Backbone.js context I would do something like this :

var sub1 = Meteor.subscribe('foo'),
sub2 = Meteor.subscribe('bar');
$.when(sub1, sub2, function(){
    // do things
});

but I think this is not the Meteor way... (?) I could do something like this

Meteor.subscribe('foo', function(){
    Meteor.subscribe('bar', function(){
        // do things
    });
});

but this quickly gets messy. There is probably some kind of helper/pattern for doing this and I just don't know it...

NB - I am using the outstanding iron-router, and have also tried this :

this.route('baz', {
    // code ...
    'before' : [
        function(){
            this.subscribe('foo').wait();
        },
        function(){
            this.subscribe('bar').wait();
        }
     ],
     // more code ..
 });

but this doesn't seem to prevent downstream code from running, and so doesn't solve my problem...

Was it helpful?

Solution

It turns out the old way isn't working. This one does though. I'm using it for my callback bin at http://sa.gy

this.route('baz', {
    before: function(){
        this.subscribe('foo').wait();
        this.subscribe('bar').wait();
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top