فهرست منبع

Commit 12-6: Use a single post subscription to ensure that we can always see the right post.

Frederic G. MARAND 9 سال پیش
والد
کامیت
027d6dc596
2فایلهای تغییر یافته به همراه10 افزوده شده و 2 حذف شده
  1. 4 1
      lib/router.js
  2. 6 1
      server/publications.js

+ 4 - 1
lib/router.js

@@ -43,7 +43,10 @@ PostsListController = RouteController.extend({
 Router.route('/posts/:_id', {
   name: 'postPage',
   waitOn: function () {
-    return Meteor.subscribe('comments', this.params._id);
+    return [
+      Meteor.subscribe('comments', this.params._id),
+      Meteor.subscribe('singlePost', this.params._id)
+    ];
   },
   data: function () {
     // "this" is the matched route.

+ 6 - 1
server/publications.js

@@ -1,5 +1,5 @@
 Meteor.publish('posts', function (options) {
-  // It would probably be safe to pass sort and limit as 2 separate params.
+  // It would probably be safer to pass sort and limit as 2 separate params.
   check(options, {
     sort: Object,
     limit: Number
@@ -7,6 +7,11 @@ Meteor.publish('posts', function (options) {
   return Posts.find({}, options);
 });
 
+Meteor.publish('singlePost', function (postId) {
+  check(postId, String);
+  return Posts.find(postId);
+});
+
 Meteor.publish('comments', function (postId) {
   check(postId, String);
   return Comments.find({