-
-
Save jboulhous/4203663 to your computer and use it in GitHub Desktop.
Meteor "Join" - Javascript
This file contains 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.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() |
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
in Javascript (form coffeescript.org)