A single post is not reactive
sungwoncho opened this issue · comments
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.
Thanks @arunoda !
@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.