Skip to content

Instantly share code, notes, and snippets.

@jboulhous
Forked from tmeasday/gist:4042603
Created December 4, 2012 13:03
Show Gist options
  • Save jboulhous/4203663 to your computer and use it in GitHub Desktop.
Save jboulhous/4203663 to your computer and use it in GitHub Desktop.
Meteor "Join" - Javascript
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()
@jboulhous
Copy link
Author

i did not yet test this Javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment