3

I have a Meteor application and I want be able to check on the client side when all the changes made by the client to a published Collection have been written to the server.

I've looked at minimongo and the code in the ddp-server, but I don't see any straightforward way to tell when the changes have been successfully written to the server.

Minimongo outline the process for saving data:

  • User triggers an interaction on the client
  • The simulation applies some mutations to the state locally
  • The RPC is fired to be executed on the server
  • After some time, the RPC returns with the result
  • After some more time, RPC returns an "updated" message (on DDP level), meaning that all the changes from RPC have persisted
  • At this point we know, that all the actual changes from the server are synced, we can throw away the simulated mutations (preserving the real changes from the server)

I can override LocalCollection.prototype.saveOriginals and LocalCollection.prototype.retrieveOriginals to know when they are each called, but I'm not sure how to verify when the data is actually saved. retrieveOriginals is getting called even when the Meteor server is down.

Is there any other place to hook a callback in or listen for an event to know when changes are synched?

Peter
  • 31
  • 2
  • Are you using a Meteor method? The collection mutations are implemented as methods internally anyway. If you need to know the collection state for a specific case (and not for any operation in your app), you can either use the method callback to report when the change is complete or make the client-side method stub add some property to each collection item to mark its temporary state. – MasterAM Nov 21 '15 at 15:01
  • I'm not using Meteor methods to perform the inserts and updates. I'm making the changes directly to the subscribed to collections. I'd like to be able to know when the changes to the location collections are synced with the server. – Peter Nov 22 '15 at 17:20
  • You can add callback to insert/update operations on the clients, which are called when the (auto-generated) method call is complete. I believe that the data is patched by then on the client as well, but you can easily test it yourself if this is important to you. – MasterAM Nov 22 '15 at 20:17

1 Answers1

0

If you're looking to implement custom observation, perhaps this might help :

Establishes a live query that invokes callbacks when the result of the query changes. The callbacks receive the entire contents of the document that was affected, as well as its old contents, if applicable. If you only need to receive the fields that changed, see observeChanges.

http://docs.meteor.com/#/full/observe or http://docs.meteor.com/#/full/observe_changes

In addition you're probably looking to use Mongo's writeConcern with Meteor, that I'm not sure how, but hope the tip helps; https://docs.mongodb.org/v3.0/reference/method/db.collection.save/

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
Perspective
  • 642
  • 5
  • 12
  • If the client side update is accepted by the server, the ddp message to the client will not need to make any further changes to the client side collection. In this case, will the `observe` callback be executed? – JeremyK Nov 21 '15 at 04:07
  • I need to be able to tell when a write to any collection is completed. The `observe` method looks like it only operates on a single cursor. – Peter Nov 22 '15 at 17:17