Hey guys,
I’m having some issues with the waitOn()
function of Iron-Router. I’ve the following route:
Router.configure({
layoutTemplate: 'android',
progressSpinner : false,
loadingTemplate:'loading',
waitOn: function() { return [subs.subscribe('me'),subs.subscribe('friends')] }
});
Router.route('/me', {
name: 'me',
data: function() { return Meteor.user(); },
waitOn: function() { return subs.subscribe('me'); }
});
For subscriptions, I’m using the SubsManager
plugin. For publish, I’m using the publishComposite
plugin, f.e.
Meteor.publishComposite("me", {
find: function () {
return Meteor.users.find({_id: this.userId});
},
children: [
{
find: function (user) {
return Images.find({owner: user._id});
}
},
{
find: function (user) {
return Requests.find({user2: user._id});
},
children:
[
{
find:function(request)
{
return Meteor.users.find({_id: request.user1});
},
children: [
{
find: function(user) {
return Images.find({_id:user.profile.picture});
}
}
]
}
]
}
]
Now I’m having the following issue. In my template, I try to access the images (CollectionFS):
Template.me.onRendered(function() {
console.log(Images.find({owner:Meteor.userId()}).count());
});
I get 0 results. If I try it again with a timeout of 3 seconds, I get 10 results. If I remove the subscription from Router.configure
, it works fine, again. My question is: Why isn’t it possible to add my subscription only to my “layout template” via Router.configure? I need this subscription on every site, but it must be safe that it is ready.
//Edit: Okay, the “layoutTemplate” renders after the “me” template. So I think that’s the problem. Is there any good solution to handle this case? How can I use a subscription globally without subscribing on every single route and wait until it’s ready?