Prechádzať zdrojové kódy

Commit 10-4: Made a simple publication/subscription for comments.

Frederic G. MARAND 9 rokov pred
rodič
commit
ae5ca11884
2 zmenil súbory, kde vykonal 9 pridanie a 6 odobranie
  1. 4 4
      lib/router.js
  2. 5 2
      server/publications.js

+ 4 - 4
lib/router.js

@@ -12,10 +12,7 @@ Router.configure({
   loadingTemplate: "loading",
   notFoundTemplate: "notFound",
   waitOn: function () {
-    return [
-      Meteor.subscribe('posts'),
-      Meteor.subscribe('comments'),
-    ];
+    return Meteor.subscribe('posts');
   }
 });
 
@@ -27,6 +24,9 @@ Router.route('/', {
 
 Router.route('/posts/:_id', {
   name: 'postPage',
+  waitOn: function () {
+    return Meteor.subscribe('comments', this.params._id);
+  },
   data: function () {
     // "this" is the matched route.
     return Posts.findOne(this.params._id);

+ 5 - 2
server/publications.js

@@ -11,6 +11,9 @@ Meteor.publish('posts', function() {
   return Posts.find();
 });
 
-Meteor.publish('comments', function() {
-  return Comments.find();
+Meteor.publish('comments', function(postId) {
+  check(postId, String);
+  return Comments.find({
+    postId: postId
+  });
 });