Hello everybody
I have a question about how meteor pubsub is working internally.
Imagine we have a Projects
collection. It contains documents like this:
{
_id: "1",
metadata: {
createdAt: 121323123,
someOtherData: "Some Data"
}
}
We are subscribed to a complete document.
Now we have a method that does the following:
Projects.update("1", { $set: { 'metadata.createdAt': Date.now() } });
I would expect Meteor to send a ddp message via websocket containing something like:
{
"msg": 'changed',
"collection": 'projects',
"id": "1",
"fields": { "metadata.createdAt": newValue }
}
But it’s instead sending this:
{
"msg": 'changed',
"collection": 'projects',
"id": "1",
"fields": {
"metadata": {
"createdAt": newValue,
"someOtherData": "Some Data",
}
}
}
I thought meteor would send a message only for the single path that was changed, but it seems to send a message about the entire subdocument.
If this is so, i don’t see the difference between making a $set: { 'metadata': newObject }
and setting only the field as done before.
This is causing problems in the following case. Imagine we have a template that’s rendering a text input showing the data in someOtherData
. You can start writing that input and onBlur
the data will be saved. But while you are writing, some other method changes the value of createdAt
inside metadata
. The the local collection is updated again to the values, and because the input is rendering the someOtherData
value and depends on that, it will be rerendered and your input will be lost, even if that field was not really changed.
@sashko or anybody, please tell me