Meteor-EventDDP icon indicating copy to clipboard operation
Meteor-EventDDP copied to clipboard

Does it work in a simple javascript function?

Open mgrivera opened this issue 8 years ago • 1 comments

Hi,

I use this package from meteor methods, to send events to the client that calls that method. It has worked well, I suppose, and I've use it several times this way.

Now I have this long code with is part of a Meteor Method. To make all that code more readable, I just want to put it in several functions. Those functions will exist in the same js file as the Meteor Method and will be called from the Meteor Method itself.

My problem is, it seems, the events are not fired and sent to the client if they reside in functions, instead in the meteor method directly. I suppose this has to do with how ddp is implemented. Maybe the events can be sent though ddp only if they reside in Meteor Methods. I really don´t know for sure.

So, my question is: How, can I send this events from functions, which are called from the meteor method, in the same way as when they are written just in the methods?

Many thanks and bye ...

mgrivera avatar Apr 21 '16 15:04 mgrivera

good question - try wrapping the emit in a Meteor.defer or maybe in a setTimeout(()=>{}, 0) (there might be an issue with connection context)

raix avatar May 06 '16 07:05 raix