I want to decide based on a boolean attribute in a document (mode
), which subscriptions the user gets, but I have problems with the design approach. If I use this.data()
and a if clause in the waitOn
function, I will get the 404 page rendered, because I need first the subscription.
Here is my code:
this.route('gamePage', {
path: '/game/:slug/viewGame/:produceDate?/:releaseDate?',
onBeforeAction: [memberFilter],
waitOn: function() {
var game = this.data();
if (game.mode) {
if (this.params.produceDate && this.params.releaseDate) {
return [Meteor.subscribe('singleGame', this.params.slug),
Meteor.subscribe('authorsMode', this.params.slug, this.params.produceDate, this.params.releaseDate)];
} else {
return [Meteor.subscribe('singleGame', this.params.slug), Meteor.subscribe('console', this.params.slug)];
}
} else {
return [Meteor.subscribe('singleGame', this.params.slug),
Meteor.subscribe('authors', this.params.slug)];
}
},
data: function() {
return Games.findOne({slug: this.params.slug});
}
Any help would be greatly appreciated.