Skip to content

Instantly share code, notes, and snippets.

@czbaker
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save czbaker/f46b4ba1773c4a9be24c to your computer and use it in GitHub Desktop.

Select an option

Save czbaker/f46b4ba1773c4a9be24c to your computer and use it in GitHub Desktop.
Template.layout.onCreated(function() {
var follows = Follows.find({owner: this.userId}, { fields: { uid: 1 }}).map(function(doc) {
return doc._id;
});
console.log(follows);
Events.find( { uid: { $in: follows } }).observe({
added: function(doc) {
sAlert.success("New event created!")
}
});
});
// Base configuration
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'spin',
waitOn: function() {
return [
Subs.subscribe('categories'),
Subs.subscribe('userFollows'),
Subs.subscribe('followedActivity')
];
}
});
// Publications
Meteor.publish('userFollows', function() {
return Follows.find({owner: this.userId});
});
Meteor.publish('followedActivity', function() {
if (this.userId) {
// Get the user's follows, then pluck the IDs only.
var follows = Follows.find({owner: this.userId}, { fields: { uid: 1 }}).map(function(doc) {
return doc._id;
});
return Events.find( { uid: { $in: follows } } );
} else {
this.ready();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment