Add wildcard support for events
It would be great if you could use a wildcard to capture all events. For example:
client.on("*", function(data) {
}
agreed.
EventEmitter2
+1 This would allow us to create filters and what not for all events.
- another dependency
- must be reflected at client side (code?)
- should catchall be called before particular event? or in the order of definition? clarification needed
- only sync behavior -- wouldn't it be better to introduce custom async filters for events?
+1
only sync behavior -- wouldn't it be better to introduce custom async filters for events? @dvv
I'm quite interested in this idea.
some of the EE2 choices are not what I would consider ideal but I +1 the general idea of this, even if only "*" is supported
truly catchall: manager.on("event", function(client, event, data) {} -- will also allow to reduce number of closures
i don't remember any resistance to just adding a catchall listener, the only debate I remember was whether or not we use "*" or if we go with another method name like .addGlobalListener()
+1 I too would need a way to intercept all events, and have the specific handler get a look at them, only once I'm done processing it. Mostly for logging purposes would this be needed. Socket.io logger currently only logs to the console, and in a very self righteous way. dvv -s approach is really to my liking. In fact maybe it would be a good idea to have us relay the event to any specific handler, and we just get all events, as described by dvv.
Please get this issue in motion :) Would love to see this feature implemented.
Well, ok, I just added EE2 to a branch in my fork: https://github.com/einaros/socket.io/commit/2107ff00f3ddf2d781d3e3c3b7dfb1fc990f7ec5
The branch is at: https://github.com/einaros/socket.io/commits/ee2
Thoughts are most welcome.
if EE2 gets rid of the weird method names and adds .on('*') I'd +1 that
I'm a -1 on EE2
It adds more bloat to the code, we also need to support it on the client side. Which means we would have to ship a extra 11.8 KB library (minified ~3.5kb). But with the up coming mobile market I would like to save as much bytes as possible.
If this is really only about having a wildcard / catch all listeners.. Then this should be done by overriding the existing emit function that just does one extra call to a all listener. This would be like a 3 - 5 LOC change (excluding comments ;)). And should be hidden behind a preference lock as it influence performance. EventEmitting is a hot code path and should always be as optimal and fast as possible. Adding wildcards will degrade performance.
catch-all is definitely the more important part, it's easy enough to switch on the event after that if necessary
Don't really care about wildcard's, or EE2, but a way, to intercept all events is a must.
if EE2 ... adds .on('*') I'd +1 that
TJ you crazy bro...
server.on('foo.*', function(value1, value2) {
console.log(this.event, value1, value2);
});
That's from the README of EE2. Naturally, the "foo." is optional.
if EE2 gets rid of the weird method names
I agree.
@pyrotechnick the EE2 .on('*') isnt a catch-all iirc
* is not catch-all in the sense that it blindly catches all events but it does effectively catch all events since the pattern * matches all channels.
It's inefficient; but it does work as expected.
I was mistaken. You're right...
{EventEmitter2} = require 'eventemitter2'
emitter = new EventEmitter2 wildcard: on
emitter.on '*', ->
console.log @event, arguments...
emitter.emit 'foo'
emitter.emit 'foo.bar'
isabel:hydrogen pyrotechnick$ coffee test.coffee
foo
I almost prefer this behaviour when it comes to wildcards though.
When I think about all of this wildcard/"namespaced" events stuff it kind of makes me sad; JavaScript already has a fantastic way to match patterns -- they live in // or are constructed with RegExp. Is this just too slow?
Can I +1 the importance of this again. I'd love to see this in an upcoming release.
Someone posted a solution here: http://stackoverflow.com/questions/8832414/overriding-socket-ios-emit-and-on/8838225