-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add an onMany method to attach a callback to multiple socket events. #1594
Comments
Hi! This should be sufficient: function onMany(socket, events, handler) {
events.forEach(e => {
socket.on(e, handler);
});
}
onMany(socket, ["foo", "bar"], () => { /* ... */ }); What do you think? |
zoosphar
changed the title
Sponsored issue: Add an onMany method to attach a callback to multiple socket events.
Add an onMany method to attach a callback to multiple socket events.
Nov 21, 2023
I identified some potential issues with the solution you proposed
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When emitting multiple events of a similar functionality from the server, One has to apply a 'socket.on' listener to each one of them. Rather than what will be feasible is to have an onMany method which will take in an array of all the expected events and then fire the callback if any of the event is being emitted from the server.
The text was updated successfully, but these errors were encountered: