0

i reuse the same template in other route with different data argument but using the same publication...

if i do normal pub/sub, the data being published as expected. but when i do conditional pub/sub like below, i fail to subscribe the data. console log return empty array,,,

server/publication.js

Meteor.publish('ACStats', function(cId, uId) {
    var selectors = {cId:cId, uId:uId};
    var options = {
        fields: {qId:0}
    };
    return ACStats.find(selectors,options);
});

client/onCreated

Template.channelList.onCreated(function() {
  this.disable = new ReactiveVar('');
  if (FlowRouter.getRouteName() === 'profile') {
    var self = this;
    self.autorun(function() {
      var penName = FlowRouter.getParam('penName');
      var u = Meteor.users.findOne({slugName:penName});
      if (u) {var uId = u._id;}
      Meteor.subscribe('ACStats', null, uId);
    });
  } else{
    var self = this;
    self.autorun(function() {
      var channelName = FlowRouter.getParam('channel');
      var c = Channels.findOne({title:channelName});
      if (c) {var cId = c._id;}
      Meteor.subscribe('ACStats', cId, null);
    });
  }
});

console

ACStats.find().fetch() //return empty array

anyone have figured out my mistake ..??

thank You so much....

  • 1
    There are a couple places where you could have errors. (1) Your finds for `Meteor.users` or `Channels` return no results. (2) Your `ACStats` documents have `cId` or `uId` *missing* instead of defined as `null`. – Michel Floyd Dec 05 '15 at 19:31

1 Answers1

0

You can make two publications:

Meteor.publish ('ACStatsChannels', cId, function() {
});
Meteor.publish ('ACStatsUsers', uId, function() {
})

And then subscribe like this:

Template.channelList.onCreated(function() {
   this.disable = new ReactiveVar('');
   var self = this;
   self.autorun(function() {
      if (FlowRouter.getRouteName() === 'profile') {
          var penName = FlowRouter.getParam('penName');
          self.subscribe('ACStatsUsers', penName);
      } else {
          var channelName = FlowRouter.getParam('channel');
          self.subscribe('ACStatsChannels', channelName);
    }
  });
});
  • heloo,, @ViktorMarinov thanks for your answer,,,, yapp this is what i implement currently... i suspect null argument in meteor subscription isn't supported yet... i post the detail here: https://forums.meteor.com/t/pass-null-argument-on-subscription/15143 ... have a comment..?? –  Jan 13 '16 at 20:52