0

How do I prevent the last template's data from displaying in the next template/route?

I'm having the issue of the last route/template's data rendering in the next until the query is returned. Is this what waitOn is for?

I've tried using waitOn, but this route is supposed to be reactive so I don't want the entire route re-rendering.

Note: this question is different than: meteorjs iron-router waitOn and using as data on rendered because I'm not using a Collection.find({}) query, I'm using a this.subscribe('publication') type query.

Currently my route is structured like so and this works but it renders other content collection data in it before the subscription is complete:

this.route('news', {
  path: '/news',
  template: 'contentList',
  data: function () {

  var content = this.subscribe('content-topics', Session.get('topics'), contentTopicsItemLimit);
  var macroTopics = this.subscribe('macro-topics');

  var data = {
    macroTopics: macroTopics,
    content: content
  };
  return data;

  }
});

I've tried using waitOn, but I'm not sure how to structure that with this type of query.

So what is the best way to structure this while maintaining the reactivity?

Community
  • 1
  • 1
JohnAllen
  • 7,317
  • 9
  • 41
  • 65

1 Answers1

0

Try

waitOn: function() { 
    return [Meteor.subscribe('content-topics', Session.get('topics'), contentTopicsItemLimit),
    Meteor.subscribe('macro-topics')] 
}

this should render only after the data from both subscriptions is brought to the client.

  • Andreas: I had tried pretty much this. The problem with this is that it fully reloads the page and also it messes up my session variable there for some reason (that part may be unrelated and fixable). But the user can select various topics here - one or many topics - so I'd rather the page not fully reload here, just to refresh the content. – JohnAllen Sep 20 '14 at 05:23
  • you mean changing to use waitOn causes a full page refresh - like reloading the URL in the browser? i don't see that behavior using waitOn. you're sure it's not in the formatting of the link targeting that page? – dcsan Sep 21 '14 at 16:58
  • I don't see that behaviour either. Just changes the parts of the page according to the router definition. Maybe you are not using {{>yield}} in order to render the route inside a part of your page and thus the entire page is reloaded? Can you post an example of your templates - contentList and the main template? – Andreas Fruth Sep 23 '14 at 20:22