Skip to content
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

Accessing event name in callback #44

Open
andrew-aladev opened this issue Oct 4, 2016 · 3 comments
Open

Accessing event name in callback #44

andrew-aladev opened this issue Oct 4, 2016 · 3 comments

Comments

@andrew-aladev
Copy link

andrew-aladev commented Oct 4, 2016

['event1', 'event2']
.forEach(function (event) {
  socket.data(event, data.bind(self, event));
})

But what about generic event names? It is not possible to predict event. We've found a way in examples:

outbound.data(['drink', '*'], function () {
  console.log('I can mix a', this.event[2], 'drink');
});

There is no information about this.event in docs. This is very important, please fix.

@andrew-aladev
Copy link
Author

BTW What is the reason of having socket.event = [ 'data', 'present' ]? This is done by EventEmitter2. What socket want to do with event? This is the awful workaround.

@nucleardreamer
Copy link
Member

It would probably be helpful to add some information to the readme about this.event in the EE callback, but nssocket is not particularly concerned with what you do with the data after it gets fired. The reason that exists in the EventEmitter2 scope is specifically for wildcards.

On your second comment, I have no idea what you mean. Could you provide clarity of what is a workaround?

@andrew-aladev
Copy link
Author

@nucleardreamer, See here. I am sure that some programmer passed this.event as temporaly workaround but community decided this to be a "pattern". This is funny. Please do not use this part of "pattern".

socket.event means the last event name on the socket. Any setImmediate (for example Promise) will make socket.event meaningless for current event handler.

socket.data(['iam', 'here'], function (data) {});

You want to provide data as 1-st argument. Why second argument couldn't be a event?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants