Permalink
Browse files

Use a single post subscription to ensure that we can always see the r…

…ight post.

chapter12-6
  • Loading branch information...
tmeasday committed Nov 26, 2013
1 parent 55a5168 commit cda6c6efd4040a830fe1ff9b50ce415fbedc16d1
Showing with 13 additions and 2 deletions.
  1. +7 −2 lib/router.js
  2. +6 −0 server/publications.js
View
@@ -33,17 +33,22 @@ PostsListController = RouteController.extend({
}
});
-
Router.route('/posts/:_id', {
name: 'postPage',
waitOn: function() {
- return Meteor.subscribe('comments', this.params._id);
+ return [
+ Meteor.subscribe('singlePost', this.params._id),
+ Meteor.subscribe('comments', this.params._id)
+ ];
},
data: function() { return Posts.findOne(this.params._id); }
});
Router.route('/posts/:_id/edit', {
name: 'postEdit',
+ waitOn: function() {
+ return Meteor.subscribe('singlePost', this.params._id);
+ },
data: function() { return Posts.findOne(this.params._id); }
});
View
@@ -6,6 +6,12 @@ Meteor.publish('posts', function(options) {
return Posts.find({}, options);
});
+Meteor.publish('singlePost', function(id) {
+ check(id, String);
+ return Posts.find(id);
+});
+
+
Meteor.publish('comments', function(postId) {
check(postId, String);
return Comments.find({postId: postId});

0 comments on commit cda6c6e

Please sign in to comment.