It's relatively simple: there's no merging or conflict resolution involved.
Before sending any insert, update, or remove method, Meteor saves a
snapshot of the affected collection.
Then, during the execution of the method (in fact, any method), all
updates to all collections on the server are buffered rather than
applied to the local caches. Further client-side operations are
performed on the local caches and send further methods.
Once *all* outstanding methods are finished (and any new subscriptions
have received their initial contents), the following steps happen:
- All collections are disconnected from any reactive contexts that
may be observing them
- All collections with snapshots are restored to that snapshot
- All buffered updates are applied
- The reactive contexts are restored to the collections, which now
observe any changes from this process as a single change
Example 2: The case of a users.update({favColor: "blue"}, {$set:
{favColor: "green"}}), where Liron's favorite color was blue but is
changed concurrently to red.
1) The client saves a snapshot of Meteor.users.
2) The client updates Liron's favorite color from blue to green in the
local cache, and sends an update({favColor: "blue"}, {$set: {favColor:
"green"}}) method call to the server.
2b) The server, for some other reason, changes Liron's favorite color to red.
2c) The server sends the client a "set Liron's favorite color to red"
(which is buffered because of the outstanding method).
3) The server tries to apply the update, but nothing changes because
nobody's favorite color is blue.
4) Nothing is added to the write fence.
5) No further data update messages are sent.
6) Now that all the (nonexistent) conditions of the "write fence" have
been completed, the server tells the client that the method has
completed.
7) The client disconnects the collection from the reactive context.
8) The client restores the snapshot, so Liron's favorite color is blue again.
9) The client applies the buffered "set it to red" message.
10) The client reconnects the collection to the reactive context. The
reactive context observes a change from blue to red, so redraws
anything that was depending on the color.
Does that make sense? (The write fence part is an internal detail of
the server and if it's confusing you can ignore it.)
> --
> You received this message because you are subscribed to the Google Groups
> "meteor-talk" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/meteor-talk/-/xshyftyFr70J.
> To post to this group, send email to
meteo...@googlegroups.com.
> To unsubscribe from this group, send email to
>
meteor-talk...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/meteor-talk?hl=en.