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

Socket has hardcoded "message" event #9

Open
graforlock opened this issue Aug 31, 2018 · 2 comments
Open

Socket has hardcoded "message" event #9

graforlock opened this issue Aug 31, 2018 · 2 comments

Comments

@graforlock
Copy link

graforlock commented Aug 31, 2018

I believe Socket.on is not generic enough, as it stand now it is:

let on = (socket, func) =>
      _on(socket, "message", obj => func(Json.fromValidJson(obj)));

But looking at the docs Socket.IO Documentation, socket.io should support different types of events:

io.on('connection', function(socket){
  socket.emit('request', /* */); // emit an event to the socket
  io.emit('broadcast', /* */); // emit an event to all connected sockets
  socket.on('reply', function(){ /* */ }); // listen to the event
});

So the above would be like this:

let on = (socket, event, func) =>
      _on(socket, event, obj => func(Json.fromValidJson(obj)));

The design decision here is however to support switch statement match; shouldn't user have option to do it the standard way through optional parameter?

@bsansouci
Copy link
Collaborator

Hey! Yup the design is to enable pattern matching, and socket.io’s design is closely tied to JS and it’s semantics. Why would you like to send stringly-typed messages?

One good reason could be to communicate with an existent backend/frontend. In which case I could imagine exposing some unsafe functions.

@graforlock
Copy link
Author

graforlock commented Aug 31, 2018

Yes that is correct, if either is in another language or stack, the API should provide some flexibility for such case.

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