Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Meteor "Join" -- Note that this code is *not* production ready.
Meteor.publish 'paths', (since) ->
pointHandles = {}
publishPath = (pathId) =>
pointHandles[pathId] = Points.find({pathId: pathId}).observe
added: (obj) =>
@set('points', obj._id, obj)
@flush()
# these two should never happen
changed: (obj) =>
@set('points', obj._id, obj)
@flush()
removed: (old_obj) =>
@unset('points', old_obj._id, _.keys(old_obj))
@flush()
pathHandle = Paths.find({createdAt: {$gt: since}}).observe
added: (obj) =>
@set('paths', obj._id, obj)
@flush()
publishPath(obj._id)
# in general this should be smarter, but shouldn't happen much
changed: (obj) =>
@set('paths', obj._id, obj)
@flush()
# this should never happen, but just in case
removed: (old_obj) =>
pointHandles[old_obj._id].stop()
@unset('paths', old_obj._id, _.keys(old_obj))
@flush()
@complete()
@flush()
@onStop =>
handle.stop() for handle in pointHandles
pathHandle.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.