Open thearabbit opened 9 years ago
I'm not sure what you mean. All "before hooks" run directly after eachother. The "Denormalize hooks" run after any "after hooks" inside a Meteor.defer
. Depending on what you do in your "before hooks", you might trigger another "Denormalize hook" run though...
I create own hook like this
// Server
Comments.before.insert(function (userId, doc) {
console.log('before insert');
});
Comments.before.update(function (userId, doc, fieldNames, modifier, options) {
console.log('before update');
});
When I click insert via autoform
, It run on both hook
before insert
before update
And then I try remove .cacheDoc()
on Comments, it work fine.
Ah, that's because .cacheDoc()
calls Comments.update()
, so before.update
is called everytime a cached field updates.
I do need this options.
You could try direct.update()
, I am not sour (I discussed in meteor forums about this).
Or you have any solutions, I will waiting for you updated.
You can use the fieldNames
to skip the hook if it's just the cache field that's being updated:
Comments.before.update(function (userId, doc, fieldNames, modifier, options) {
if(_.without(fieldNames, '_post').length > 0) {
console.log('before update');
}
});
Could you update your package to support this???
I use Collection Hook for all Collections, so I do this (above) for many time.
It have problem or not, if I update only reference field (not any fields).
Sorry for the late reply. Is this still an issue for you or have you been able to resolve it?
For example I have hooks on Comments such as
before.insert() and before.update()
. When I click on submit to insert, both of my hooks run all at the same time. Please help me.