Permalink
Browse files

Added comments collection, pub/sub and fixtures.

chapter10-1
  • Loading branch information...
tmeasday committed Apr 8, 2013
1 parent b9f7042 commit db88c3fd0f3910b894d4352bb567d230e2db63e6
Showing with 52 additions and 6 deletions.
  1. +2 −0 lib/collections/comments.js
  2. +3 −1 lib/router.js
  3. +42 −4 server/fixtures.js
  4. +5 −1 server/publications.js
@@ -0,0 +1,2 @@
+Comments = new Mongo.Collection('comments');
+
View
@@ -2,7 +2,9 @@ Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
- waitOn: function() { return Meteor.subscribe('posts'); }
+ waitOn: function() {
+ return [Meteor.subscribe('posts'), Meteor.subscribe('comments')];
+ }
});
Router.route('/', {name: 'postsList'});
View
@@ -1,16 +1,54 @@
+// Fixture data
if (Posts.find().count() === 0) {
- Posts.insert({
+ var now = new Date().getTime();
+
+ // create two users
+ var tomId = Meteor.users.insert({
+ profile: { name: 'Tom Coleman' }
+ });
+ var tom = Meteor.users.findOne(tomId);
+ var sachaId = Meteor.users.insert({
+ profile: { name: 'Sacha Greif' }
+ });
+ var sacha = Meteor.users.findOne(sachaId);
+
+ var telescopeId = Posts.insert({
title: 'Introducing Telescope',
- url: 'http://sachagreif.com/introducing-telescope/'
+ userId: sacha._id,
+ author: sacha.profile.name,
+ url: 'http://sachagreif.com/introducing-telescope/',
+ submitted: new Date(now - 7 * 3600 * 1000)
+ });
+
+ Comments.insert({
+ postId: telescopeId,
+ userId: tom._id,
+ author: tom.profile.name,
+ submitted: new Date(now - 5 * 3600 * 1000),
+ body: 'Interesting project Sacha, can I get involved?'
+ });
+
+ Comments.insert({
+ postId: telescopeId,
+ userId: sacha._id,
+ author: sacha.profile.name,
+ submitted: new Date(now - 3 * 3600 * 1000),
+ body: 'You sure can Tom!'
});
Posts.insert({
title: 'Meteor',
- url: 'http://meteor.com'
+ userId: tom._id,
+ author: tom.profile.name,
+ url: 'http://meteor.com',
+ submitted: new Date(now - 10 * 3600 * 1000)
});
Posts.insert({
title: 'The Meteor Book',
- url: 'http://themeteorbook.com'
+ userId: tom._id,
+ author: tom.profile.name,
+ url: 'http://themeteorbook.com',
+ submitted: new Date(now - 12 * 3600 * 1000)
});
}
View
@@ -1,3 +1,7 @@
Meteor.publish('posts', function() {
return Posts.find();
-});
+});
+
+Meteor.publish('comments', function() {
+ return Comments.find();
+})

3 comments on commit db88c3f

@HmadAmani

This comment has been minimized.

Show comment
Hide comment

kkjjjjj

@HmadAmani

This comment has been minimized.

Show comment
Hide comment

wd

@HmadAmani

This comment has been minimized.

Show comment
Hide comment

khjdi

Please sign in to comment.