Friday 28 April 2017

How does SocketIO have generic .on() events for any given event?

When using SocketIO, receiving any message is done as so:

socket.on("eventname", function() {
    // Whatever
}

But "eventname" can be literally any string of text.

How did they achieve that? How do they have an event listener for each and every possible string? Do they add event listeners AS the messages come in?

I've tried reading the SocketIO source code, but it went right over my head.



via William Hayward

No comments:

Post a Comment