Replacing Collection Hooks and Callbacks with Native Node Events?


#1

In various articles and talking with different users - it has been suggested that the meteor-collection-hooks package and it’s patterns could be replaced by Node.js’s native Events module.

So instead of having a collection hook that inserts/updates/removes documents after another document’s insert/update/remove and/or using asynchronous nested callbacks to update a document once a previous update to a document occurs, you can use Node.js Events with emitters and listeners that can perform your “clean up” for you.

I’m assuming it’s something like:

Objects.update({...}, {$set: {...}}, function(error) {
   if(!error)
      //  Emit Node Event Here
});

Or perhaps in a collection hook you would fire an event? Then you have a listener function defined somewhere.

Is anyone using this pattern? Do you have any examples? Are you finding it better than something like meteor-collection-hooks or using nested callback document updates?

I’m curious. Does Meteor use the Node.js Events module already under the hood?


#2

Just bumping and adding another thought…

One of the awesome things about matb33:collection-hooks is you can call things like:

someCollection.before.update

This is so powerful because you can check for things before an update and then modify the $set modifier (for example) for updating all in one fell swoop. This is just one example of the flexibiity of collection hooks.

How would a before.update even be achieved using events? Is there some way to have an update that some how triggers and event to occur before the update finishes? And if so, how do you combine them cleanly and only have one update? It doesn’t seem like it would be as smooth and clean as collection hooks.

I’m a little bummed out because matb33:collection-hooks hasn’t had a commit in almost a year and a half and I myself have two open bugs out for it. I should probably try to get in there and hack at them myself and submit PRs, but I usually strike out at the deeper level problem-solving. Aside from a few minor forks, this is a great package that seems to be dying off.

Anyone else use anything similar or other patterns that mimic collection hooks?


#3

I hate how fragmented and fickle the JS community is.


#4

Hit another nasty collection hooks bug today. https://github.com/matb33/meteor-collection-hooks/issues/244

@a.com What exactly is fickle about querying the community for alternative strategies in light of a major package deteriorating?


#5

This is really helpful: http://www.meteor-tuts.com/chapters/3/events.html