Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

How does this package actually work? #79

Closed artpolikarpov closed 9 years ago

artpolikarpov commented 9 years ago

I’m sorry for my incredulity! Great package. But please explain how it works.

Do you just copy-paste from original Mongo.* methods and add hooks? Or something smarter?

Meteor 1.0.1 contains a patch for a security vulnerability that could cause data loss in apps that use allow/deny rules. Will this package play well with that update or not?

Thank you.

dalgard commented 9 years ago

The readme has references to an "underlying" method; Mathieu wrote this in a different answer:

The underlying method is actually _collection.insert -- that one is available only on the server and is what I rely on to make sure hooks on the server are only called after allow/deny has had a chance to run.

matb33 commented 9 years ago

The package simply wraps the appropriate methods. It's really simple, but finding the exact right method to wrap was the initial challenge.

Pseudo-code-ish example:

function update() {
  console.log('hi');
}

var underlying = update;
update = function () {
  console.log('do something before');
  underlying.apply(this, arguments);
  console.log('do something after');
};
artpolikarpov commented 9 years ago

Thanks, @matb33!