Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A single post is not reactive #48

Closed
sungwoncho opened this issue Feb 7, 2016 · 6 comments
Closed

A single post is not reactive #48

sungwoncho opened this issue Feb 7, 2016 · 6 comments

Comments

@sungwoncho
Copy link

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?

@TimFletcher
Copy link

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);
});

@ShockiTV
Copy link
Contributor

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

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

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

@TimFletcher
Copy link

Thanks @arunoda !

@sungwoncho
Copy link
Author

@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

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

@sungwoncho Yes. And it's less code.

@arunoda arunoda closed this as completed Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants