Meteor-Community-Packages / meteor-collection-hooks

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

If multiple hooks are defined with the same type on the same collection, which of them gets run first, and which second... #210

Closed dongzhi-yang closed 7 years ago

dongzhi-yang commented 7 years ago

Hi, Suppose I have 5 different after.insert hooks defined on the same collection. In what order will they run? Is there a way I can controller this?

Thanks

namirsab commented 7 years ago

They are gonna be run in the same order they get loaded. You can control the order controlling the loading order of the files that declarethem, or controlling the loading order of the packages they are part of.

If you have all of them in the same file, they will be run in the order you declare them in that file.

Anyway, if you are writing hooks that are affecting each other, you should maybe reconsider that. Hooks should be independent and if possible. If you want a hook to run after the other want, maybe you should just put them together in the same function :smile

I hope that helps.

I close this issue because i think the problem is solved :smile:

dongzhi-yang commented 7 years ago

Awesome, thanks for the detailed answer!

On Mon, Jan 16, 2017 at 6:43am, Namir < notifications@github.com [notifications@github.com] > wrote: They are gonna be run in the same order they get loaded. You can control the order controlling the loading order of the files that declarethem, or controlling the loading order of the packages they are part of.

If you have all of them in the same file, they will be run in the order you declare them in that file.

Anyway, if you are writing hooks that are affecting each other, you should maybe reconsider that. Hooks should be independent and if possible. If you want a hook to run after the other want, maybe you should just put them together in the same function :smile

I hope that helps.

I close this issue because i think the problem is solved 😄

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub [https://github.com/matb33/meteor-collection-hooks/issues/210#issuecomment-272744007] , or mute the thread [https://github.com/notifications/unsubscribe-auth/AQMbeWXWaCBewZvG623uvHMM2CnkhndBks5rSqD7gaJpZM4LjxFk] .