Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with using observeChanges in autorun function #50

Open
kerf007 opened this issue Oct 3, 2019 · 4 comments
Open

Issue with using observeChanges in autorun function #50

kerf007 opened this issue Oct 3, 2019 · 4 comments

Comments

@kerf007
Copy link

kerf007 commented Oct 3, 2019

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.
Снимок экрана 2019-10-03 в 12 08 18

I can't understand why this happens and how to transform data before publish to client?
Help please :)

@mitar
Copy link
Member

mitar commented Oct 3, 2019

I think something else is happening. See this test which seems to work.

@kerf007
Copy link
Author

kerf007 commented Oct 3, 2019

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..

@mitar
Copy link
Member

mitar commented Oct 3, 2019

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.

@kerf007
Copy link
Author

kerf007 commented Oct 3, 2019

I created test project: https://github.com/kerf007/meteor-publish-test
The issue is reproducing or I don't understand something..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants