mantrajs / mantra-sample-blog-app

A sample blog app built with Mantra

Home Page: http://mantra-sample-blog-app.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A single post is not reactive

sungwoncho opened this issue · comments

commented

On post/:postId, the post on display is not reactive.

This may be because findOne, used here, does not return a reactive data source. How can we make it reactive?

Maybe something like this would work?

Meteor.subscribe('posts.single', postId, () => {
  const posts = Collections.Posts.find({ _id: postId }).fetch();
  let data = {};
  if (posts.length) {
    data.post = posts[0];
  }
  onData(null, data);
});

That subscribe callback is running just once anyway.
But disabling tracker on Posts.findOne few lines below is quite easy to identify....

Checkout the master branch now. It has a better version.

commented

@arunoda Why does the solution work? Is it because the subscription handle is a reactive data source, and it causes the composer to re-run when the data changes? see https://github.com/mantrajs/mantra-sample-blog-app/blob/master/client/modules/core/containers/post.js#L7

@sungwoncho Yes. And it's less code.