Dear Meteors,
I am trying to reduce the size of a subscription made from inside an iron router route with an argument passed to the corresponding publish function.
route:
Router.route('/game', {
layoutTemplate: 'masterLayout',
yieldRegions: {
'standardBorder': { to: 'border' },
'buyMenu': {to: 'buyMenuField'},
'loading': {to: 'middle'},
},
onBeforeAction: function() {
// some code
this.next();
},
subscriptions: function() {
var self = Meteor.users.findOne({
_id: Meteor.userId()
}, {
fields: {
username: 1,
}
}).username;
if(self) this.subscribe('userDataSelf', self).wait();
//this.subscribe("userData").wait();
},
action: function() {
if (this.ready()) {
this.render();
var self = Meteor.users.findOne({
_id: Meteor.userId()
}, {
fields: {
menu: 1,
cu: 1,
username: 1
}
});
var cu = self.cu;
var menu = self.menu;
if (cu == self.username) {
Router.current().render(menu + 'Base', {
to: 'middle'
});
} else {
Router.current().render(menu + 'Scrounge', {
to: 'middle'
});
else {
Router.current().render('loading', {to: 'middle'});
}
}
});
Using the above code I get the expected sub DDP message:
["{\"msg\":\"sub\",\"id\":\"cj2S9HzbpEbYQc6jA\",\"name\":\"userDataSelf\",\"params\":[\"bot20\"]}"]
But there is no document sent, it just readys the sub:
a["{\"msg\":\"ready\",\"subs\":[\"cj2S9HzbpEbYQc6jA\"]}"]
If I switch to using “this.subscribe("userData").wait();
” instead of “this.subscribe('userDataSelf', self).wait()
” I get DDP messages for all 1000 users in the database.
corresponding publish functions:
Meteor.publish("userDataSelf", function(username) {
console.log(username);
if (this.userId) {
return Meteor.users.find({
user: username
}, {
fields: {
'username': 1,
'menu': 1,
'cu': 1,
'x': 1,
'y': 1
}
});
} else {
this.ready();
}
});
Meteor.publish("userData", function() {
if (this.userId) {
return Meteor.users.find({}, {
fields: {
'username': 1,
'menu': 1,
'cu': 1,
'x': 1,
'y': 1,
}
});
} else {
this.ready();
}
});
So is it not possible to use subscriptions with arguments inside a route?
Thank you very much in advance. : )