I would appreciate some pointers on how to tackle the following.
I am using websockets to send some data from server to the client. I receive the message in Javascript (through the onmessage handler of the websocket connection), which I forward to Elm through a port. Everything is easy when this message has fixed fields. However, what is the recommended way to handle this if there can be different types of messages. Following are two examples (I am writing the JSON message):
One way I can think of is setup different ports for each kind of message and different message handlers for each type of message. Then, when the message comes from the server, I inspect the message in Javascript, and use the port and message handler based on the result of that inspection.
Is there a better way than this, or is this the recommended way?
Thank you very much for the example. I will try this and report back. I want to reiterate that the example makes it much easier to follow your solution.