Search code examples
meteorddp

Meteor and ordered collections (DDP client and observers)


I made a DDP client for meteor and implemented an ordered collection. Basically I implemented both the "added" and "addedBefore" methods from the DDP spec but I've a doubt in the proper way to interpret them. Initially, I considered the server will be using (exclusively) either "added" or "addedBefore" in a collection depending on if it is ordered or not. But it sounds a nonsense to have ordered and unordered collections. So here comes my question: should the "added" message simply be interpreted as an alias of "addedBefore" with (before == null) i.e. to be added in the very end of the collection ?

Also in the cursor.observe(callbacks) I found the following callback function added(document) or addedAt(document, atIndex, before) what do means or here ? would I be notified in both functions but for performances concern I'm just better not to put a callback on each of them ?


Solution

  • The 'ordered collections' are not in use by meteor, at least yet, from my understanding of the DDP protocol.

    The query needs to be run using the client side collections using minimongo to watch for the changes locally then fire the observer triggers. You would have to implement your own observe methods that order the incoming unordered collection data to trigger added/addedAt/addedBefore type listeners. The manner in which they would fire is up to you then.

    Even if you implemented the methods the server would never publish these, at least yet.

    This is mentioned in the current DDP spec

    NOTE: The ordered collection DDP messages are not currently used by Meteor. They will likely be used by Meteor in the future.