jagi / meteor-astronomy

Model layer for Meteor

Home Page:https://atmospherejs.com/jagi/astronomy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to update a value without telling the server?

Genroa opened this issue · comments

My case is 'simple' : I'm frequently simulating an update on the client, incrementing a counter. Every 10 seconds, the server simulates it too, but it also save the document. Problem : I don't want the client to send its simulated modifications about the counter to the server. Do you have any idea of how to do this with Astronomy objects with minimal boilerplate? :)

My only idea at the moment is making a custom Class containing only 2 values, 1 which is updated by the client frequently, and the server updates both values, so it is able to keep in mind the real old value. Or maybe findOne the same object from the database and then applying modifications based on its state?

It's not a problem of Astronomy package but Meteor in general. Meteor tries to synchronize data between client and server and from what I know there is no way of not sending this information back and forth "the easy way". So the best solution for that is decoupling client and server data stores. So you have a collection that is the same on the server and client and you synchronize data between them as normally you would do using pub/sub. However, on the client you have additional (client-only) collection that is only responsible for client simulations. On the client you update client-only collection and when you're ready to synchronize data with the server then you just rewrite this data to the synchronized collection. That's it.