Flow router and template subscriptions - multiple vs one route

So, struggling to understand if/what is wrong with my approach.
Let’s say I’m creating a todo app with teams, so there are three collections - Teams, Lists, Tasks. I want to create a columned layout, so you always see where you are and can navigate to any of the levels any time.

So, this is my only route:

FlowRouter.route('/:team?/:list?/:task?', {
   action: function() {
      BlazeLayout.render("todoLayout", {content: "todoTemplate"});
   }
});

This is my template:

<template name="todoTemplate">
   <h1>Teams</h1>

   {{#each teams}}
      {{> teamItem}}
   {{/each}}

   {{#if lists}}
      {{#each lists}}
         {{> listItem}}
      {{/each}}
   {{/if}}

   {{#if tasks}}
      {{#each tasks}}
         {{> taskItem}}
      {{/each}}
   {{/if}}
</template>

And this my template js:

Template.todoTemplate.onCreated(function() {
   var self = this;

   self.autorun(function() {
      self.subscribe('teams');
         var teamSlug = FlowRouter.getParam('team'),
             listSlug = FlowRouter.getParam('list');

      if(teamSlug){
         self.subscribe('teamLists', teamSlug);
      };

      if(listSlug){
         self.subscribe('tasks', listSlug);
      };
   });
});

Template.appMain.helpers({
    teams: function() {
       var teams = Teams.find().fetch() || {};
        return teams;
    },
    lists: function() {
        var lists = Lists.find().fetch() || {};
        return lists;
    },
    tasks: function(){
         var tasks = Tasks.find().fetch() || {};
         return tasks;
    }
})

And these are my publications:

Meteor.publish('teams', function() {
   if (!this.userId) return this.ready();
   return Teams.find({'members.userId': this.userId });
});

Meteor.publish('lists', function() {
   if (!this.userId) return this.ready();
   return  Lists.find({ 'members.userId': this.userId });
});

Meteor.publish('tasks', function(listId) {
   if (!this.userId) return this.ready();
   var list = Lists.findOne({_id:listId,'members.userId': this.userId});
   if(!list){
       return this.ready();
   } else {
       return Tasks.find({listId:listId});
   }
});

So, this is working for me. But what are the culprits in this simple approach to use just one route and let the collections to decide what to show?

Are there any performance issues?

1 Like