Created
May 29, 2012 06:50
-
-
Save tmeasday/2823011 to your computer and use it in GitHub Desktop.
Meteor Subscription timeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
at Subscribing to post#undefined; comments are: | |
at Subscribed; comments are: | |
at Startup; comments are: | |
at Subscription complete; comments are: | |
at Setting session var to 1; comments are: | |
at Set to 1; comments are: | |
at Subscribing to post#1; comments are: | |
at Subscribed; comments are: | |
at Flushed; comments are: | |
at Subscription complete; comments are: first post on #1 - second post on #1 | |
at Setting session var to 2; comments are: first post on #1 - second post on #1 | |
at Set; comments are: first post on #1 - second post on #1 | |
at Subscribing to post#2; comments are: first post on #1 - second post on #1 | |
at Subscribed; comments are: first post on #1 - second post on #1 | |
at Flushed; comments are: first post on #1 - second post on #1 | |
at Subscription complete; comments are: first post on #1 - second post on #1 - first post on #2 - second post on #2 | |
at Later; comments are: first post on #2 - second post on #2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comments = new Meteor.Collection('comments'); | |
// {post_id: '1', text: 'hi there..'} | |
if (Meteor.is_client) { | |
function log_comments(where) { | |
var cs = Comments.find({}, {reactive: false}).map(function(c) { return c.text; }).join(' - ') ; | |
console.log("at " + where + "; comments are: " + cs); | |
} | |
Meteor.autosubscribe(function() { | |
var post_id = Session.get('post_id'); | |
log_comments("Subscribing to post#" + post_id); | |
Meteor.subscribe('comments', post_id, function() { | |
log_comments('Subscription complete'); | |
}); | |
log_comments("Subscribed"); | |
}) | |
Meteor.startup(function() { | |
log_comments('Startup'); | |
// wait long enough for everything to happen | |
Meteor.setTimeout(function(){ | |
console.log(''); | |
log_comments('Setting session var to 1'); | |
Session.set('post_id', 1); | |
log_comments('Set to 1'); | |
Meteor.flush() | |
log_comments('Flushed'); | |
}, 5000); | |
// and wait even longer | |
Meteor.setTimeout(function() { | |
console.log(''); | |
log_comments('Setting session var to 2'); | |
Session.set('post_id', 2); | |
log_comments('Set'); | |
Meteor.flush() | |
log_comments('Flushed'); | |
}, 10000) | |
Meteor.setTimeout(function() { | |
console.log(''); | |
log_comments('Later'); | |
}, 15000); | |
}); | |
} | |
if (Meteor.is_server) { | |
Meteor.publish('comments', function(post_id) { | |
return Comments.find({post_id: post_id}); | |
}); | |
// add some fixture data | |
if (Comments.find().count() === 0) { | |
Comments.insert({post_id: 1, text: 'first post on #1'}); | |
Comments.insert({post_id: 1, text: 'second post on #1'}); | |
Comments.insert({post_id: 2, text: 'first post on #2'}); | |
Comments.insert({post_id: 2, text: 'second post on #2'}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment