Skip to content

Instantly share code, notes, and snippets.

@svasva
Created February 21, 2013 12:27
Show Gist options
  • Save svasva/5004404 to your computer and use it in GitHub Desktop.
Save svasva/5004404 to your computer and use it in GitHub Desktop.
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