Comments (10)
I don't know if the answer to your question specifically is yes, but there are two workarounds:
- Use the
direct
operations when you don't want to activate hooks - Use Meteor's environment variables or other global state to signal to hooks if they should do something or not (see https://github.com/mizzao/meteor-partitioner).
from meteor-collection-hooks.
When you register a hook, it returns an object with .remove and .replace. In your case you're looking for .remove
from meteor-collection-hooks.
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.
Thanks so much to both of you.
from meteor-collection-hooks.
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've tried disabling the hooks and never adding them, but I still get the error below.
CollectionFS fails, but when we look further down there is a CollectionHooks.defineAdvice.arg entry in the stack. Any thoughts?
I20140625-14:25:17.948(-7)? at Request.pipe (/Users/cram/.meteorite/packages/data-man/CollectionFS/Meteor-data-man/c42e97728b38c29522d59db58d290e928df831ba/.build/npm/node_modules/request/request.js:1299:13)
I20140625-14:25:17.948(-7)? at beginStorage (packages/cfs-collection/api.common.js:32)
I20140625-14:25:17.948(-7)? at packages/cfs-collection/api.common.js:61
I20140625-14:25:17.948(-7)? at _.each.Meteor.Collection.(anonymous function).wrappedCallback (packages/mongo-livedata/collection.js:431)
I20140625-14:25:17.949(-7)? at CollectionHooks.defineAdvice.args.(anonymous function) (packages/collection-hooks/insert.js:35)
I20140625-14:25:17.949(-7)? at Meteor.bindEnvironment.runWithEnvironment (packages/meteor/dynamics_nodejs.js:108)
I20140625-14:25:17.949(-7)? at Meteor.bindEnvironment (packages/meteor/dynamics_nodejs.js:121)
I20140625-14:25:17.950(-7)? at writeCallback (packages/mongo-livedata/mongo_driver.js:293)
I20140625-14:25:17.950(-7)? at Meteor.bindEnvironment.runWithEnvironment (packages/meteor/dynamics_nodejs.js:108)
from meteor-collection-hooks.
I believe the CollectionHooks.defineAdvice.args
always runs if collection-hooks are added, even if there are no hooks configured on the collection. Otherwise it wouldn't be able to intercept them. Why don't you look into the specific message Error: You cannot pipe after data has been emitted from the response.
? That seems to be what's causing this.
from meteor-collection-hooks.
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.
from meteor-collection-hooks.
Any luck @cramhead?
from meteor-collection-hooks.
For your specific use-case, could you wrap all of your hooks in a function that checks a variable (probably using Meteor.EnvironmentVariable
) so as to decide whether or not to run the hooks?
The idea would be that when you set this flag to false
, the function wrapping your hooks would simply short-circuit and not execute the hook. If the flag is true
, calls the hook as per normal.
from meteor-collection-hooks.
@cramhead: See https://github.com/mizzao/meteor-partitioner/blob/master/grouping.coffee#L140 for an example of how to implement @matb33's suggestion.
from meteor-collection-hooks.
Hi guys,
Thanks so much for your help. Sorry I forgot to close the issue.
I've a sample of the approach up in a gist at https://gist.github.com/cramhead/dc431ab0417fce7aa965.
The code basically listens for events emitted when seeding data and when seeding is complete. The event handlers look in a list of collection-hook handlers to determine what functions need to be removed and removes them.
I do think the issue rests in collectionFS. I'll be pursuing the collectionFS issue when I can find a small block of time.
from meteor-collection-hooks.
Related Issues (20)
- More explanation of 0.9.0 breaking changes please HOT 5
- How i can extend ALL collections? HOT 6
- After fetch hook? HOT 3
- An after.update hook's modifier doesn't get a before.update's updated modifier
- Add GitHub actions for CI HOT 2
- Using direct still causes fetchPrevious behaviour on update method
- hook "remove" does not remove hook or removes wrong hook HOT 1
- bulk update didnt trigger after update hooks HOT 3
- attach hooks to raw collections HOT 3
- Meteor 2.6: after.insert callback does not contain correct document _id HOT 2
- problem after insert doc._id object HOT 4
- Support to Meteor 2.8 and Mongo async methods HOT 5
- After update hook does not use direct find HOT 2
- Async hooks run in parallel to the collection operation HOT 3
- Meteor 3.0 migration considerations HOT 1
- Ability to add call-level parameters to hooks HOT 1
- Core dump at Meteor 3.0 alpha 15: node: ../src/coroutine.cc:134: void* find_thread_id_key(void*): Assertion `thread_id_key != 0x7777' failed. HOT 2
- Calling Meteor.userAsync inside pub throws an error in meteor 3 beta HOT 3
- before hooks and async callbacks are not compliant with Meteor 3 promises HOT 4
- Throw in before.* should also cancel the operation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-collection-hooks.