Skip to content

Instantly share code, notes, and snippets.

@SachaG
Last active June 8, 2017 15:15
Show Gist options
  • Save SachaG/7b4676b39d865aba1903e8e681acdb8a to your computer and use it in GitHub Desktop.
Save SachaG/7b4676b39d865aba1903e8e681acdb8a to your computer and use it in GitHub Desktop.
Publishing Counts
if (Meteor.isClient) {
NovaCounts = new Mongo.Collection("novacounts");
}
if (Meteor.isServer) {
NovaCounts = {
subscription: {},
counts: [],
push(listId, count, sessionId) {
this.subscription.added("novacounts", listId, {count: count});
if (!this.counts[sessionId]) {
this.counts[sessionId] = {};
}
this.counts[sessionId][listId] = count;
}
};
}
Meteor.publish('counts', function() {
const self = this;
NovaCounts.subscription = self;
self.ready();
});
Meteor.publish('posts.list', function (selector, options) {
const posts = Posts.find(selector, options);
NovaCounts.push(terms.listId, posts.count(), this._session.id);
return posts;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment