Hi all,
I already managed to use port to plug on websocket or perform API call. But only one at a time.
For a new project I need to have more than one port and I couldn’t get out of it.
Here is some pseudo code of what I want to achieve:
JS part:
const app = Elm.Main.init({ node: document.getElementById("elm") });
// ...
app.ports.comingFromJsA.send("Message from A");
// ...
app.ports.comingFromJsB.send("Response from B");
Elm part:
---- PORTS ----
port comingFromJsA : (String -> msg) -> Sub msg
port comingFromJsB : (String -> msg) -> Sub msg
---- SUBS ----
subscriptions : Model -> Sub Msg
subscriptions _ =
comingFromJsA MesgA
-- how to dispatch to "comingFromJsB MesgB" ?
---- UPDATE ----
type Msg
= MesgA String
| MesgB String
I don’t get how subscriptions are supposed to make the link between JS and ports. Put another way, how do I trigger MeagA or MesgB depending on what has been sent by JS ?
All examples I have found are trivial and only deal with one type of message.
Cheers