meteor-reactive-publish
meteor-reactive-publish copied to clipboard
Issue with using observeChanges in autorun function
Hello, Before using meteor-reactive-publish, my publish function code looked like:
let handle = cursor.observe({
added: doc => {
this.added('placeholders', doc._id, transform(doc))
},
changed: (newDoc, oldDoc) => {
this.changed('placeholders', oldDoc._id, transform(newDoc))
},
removed: doc => {
this.removed('placeholders', doc._id)
}
})
So some transformation function was used.
Then I added meteor-reactive-publish and wrapped this code in this.autorun. And now when I get DDP messages - first I get added message with some extra field from transform function, but then I get changed message that has cleared field with my extra field names and this fields are removing.

I can't understand why this happens and how to transform data before publish to client? Help please :)
I think something else is happening. See this test which seems to work.
Thanks for your feedback!
After that I install meteor-publish-composite package and did the task like this:
Meteor.publishComposite('placeholders', function() {
const self = this
return {
find() {
return Meteor.users.find({ _id: this.userId })
},
children: [
{
find(user) {
const transform = doc => {
// some transform
return doc
}
let cursor = Placeholders.find(someQuery)
let handle = cursor.observe({
added: doc => {
self.added('placeholders', doc._id, transform(doc))
},
changed: (newDoc, oldDoc) => {
self.changed('placeholders', oldDoc._id, transform(newDoc))
},
removed: oldDoc => {
self.removed('placeholders', oldDoc._id)
}
})
self.onStop(() => handle.stop())
return cursor
}
}
]
}
})
And I get the same problem - first added message and than changed with cleared field.
After that I removed meteor-reactive-publish and it's working now... But I can't figure out what was it. May be it some package incompatibility or something else..
If you can provide a small working reproduction (with the least number of packages, just those really required for reproduction), then there is a chance to help here. Otherwise not really.
I created test project: https://github.com/kerf007/meteor-publish-test The issue is reproducing or I don't understand something..