Created
February 21, 2013 12:27
-
-
Save svasva/5004404 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Meteor.publishCounter = (params) -> | |
count = 0 | |
init = true | |
id = Random.id() | |
pub = params.handle | |
collection = params.collection | |
handle = collection.find(params.filter, params.options).observeChanges | |
added: => | |
count++ | |
pub.changed(params.name, id, {count: count}) unless init | |
removed: => | |
count-- | |
pub.changed(params.name, id, {count: count}) unless init | |
init = false | |
pub.added params.name, id, {count: count} | |
pub.ready() | |
pub.onStop -> handle.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment