-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: disabling and re-enabling #47
Comments
I don't know if the answer to your question specifically is yes, but there are two workarounds:
|
When you register a hook, it returns an object with .remove and .replace. In your case you're looking for .remove |
Oh, that's awesome. Basically a handle that I can hold onto and remove handler later. I expect that will be much easier then adjusting all the collection call. |
So I think I may have stumbled across a more significant problem, assume that my code below is doing what is expected. I'm assuming that I simply call the remove method on the object returned add hood methods. Below, when adding a handlers I add push the returned object into an array when a call to initCollectionHooks is called and when disableCollectionHooks is called objects are popped from the array and their remove method is called, with no arguments. var hookHandles = [];
var initCollectionHooks = function() {
console.log('enable');
//once the seed process is complete or no seeding takes place add the listener
hookHandles.push(
Collectibles.after.insert(function(userId, doc) {
// get the imageIds and set them as being linked
App.emitter.emit('collectible.added', userId, doc);
})
);
hookHandles.push(
Collectibles.after.update(function(userId, doc, fieldNames, modifier, options) {
if (fieldNames.indexOf("favs") > -1) {
if (modifier.$push) {
collectibleFaved(userId, doc);
}
// no notification on $pop
}
})
);
};
var disableCollectionHooks = function() {
console.log('disable');
for (var i = hookHandles.length - 1; i >= 0; i--) {
console.log('removing collectible hooks');
var hookHandle = hookHandles.pop();
hookHandle.remove();
};
};
// start with hooks enabled
initCollectionHooks();
// listen for seed events and turn off/on collection hooks
App.emitter.on('seeding.started', disableCollectionHooks);
App.emitter.on('seeding.completed', initCollectionHooks); My issue seems to be an interaction between collectionFS and collection-hooks, when I attempt insert seed images.
|
I believe the |
That what I'm in process of doing. It's pretty complicated code with all the futures calls and bindEnvironment. I figure I should try disabling collection-hooks to remove it form being a potential problem first. |
Any luck @cramhead? |
For your specific use-case, could you wrap all of your hooks in a function that checks a variable (probably using The idea would be that when you set this flag to |
@cramhead: See https://github.com/mizzao/meteor-partitioner/blob/master/grouping.coffee#L140 for an example of how to implement @matb33's suggestion. |
Hi guys, I've a sample of the approach up in a gist at https://gist.github.com/cramhead/dc431ab0417fce7aa965. I do think the issue rests in collectionFS. I'll be pursuing the collectionFS issue when I can find a small block of time. |
Is there a good approach for disabling a collection hook after it has been set. I've tried setting the listeners to null or an empty function, e.g.
Collectibles.after.insert(function(){});
andCollectibles.after.insert(null);
as well asCollectibles.after.insert = null;
but the handlers I had previously set still get called or when I attempt re-enable listenersTypeError: Property 'insert' of object #<Object> is not a function
.Thanks
The text was updated successfully, but these errors were encountered: