Meteor-Community-Packages / meteor-collection-hooks

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

Question: How are you avoiding infinite loop? #221

Closed petr24 closed 7 years ago

petr24 commented 7 years ago

Hey Matt,

Wanted to know how are you avoiding an infinite loop scenario with data that's denormalized.

Example

DocA updates name, and DocA is denormalized. So when DocA is updated, I also want to update DocB and DocC with DocA's update.

So in my "after" hook, I check if DocA has any docs it needs to update. And if it does, my query is really simple. "Collection.update(query, modifier, {multi: true})" but when the update goes through, the "before" hooks are fired, but the "after" hook is not fired for DocB and DocC.

How are you preventing this? I was assuming an infinite loop scenario would be happening.

Thanks

jamesgibson14 commented 7 years ago

Yes infinite loops do happen and you have to use the direct method at some point which will not trigger the hooks.

petr24 commented 7 years ago

@jamesgibson14

Gotcha, yeah I had a if statement that prevented the infinite loop, but I had to remove it, and now get a infinite loop case.

zimme commented 7 years ago

So I'll close this for now with a note that this might need some documentation.

I'll re-open if you feel this isn't resolved.

petr24 commented 7 years ago

Yeah that works, I'll drop this link here that talks about handling the loop issue. In case someone comes across this looking for an answer. https://github.com/matb33/meteor-collection-hooks/issues/3