Here are two minimal Elm programs, that both use ports with different names:
port module A exposing (main)
port a_outgoing : String -> Cmd msg
port a_incoming : (String -> msg) -> Sub msg
main : Program () String String
main =
Platform.worker
{ init = \() -> ( "", Cmd.none )
, update = \_ s -> ( s, a_outgoing s )
, subscriptions = \_ -> a_incoming identity
}
port module B exposing (main)
port b_outgoing : String -> Cmd msg
port b_incoming : (String -> msg) -> Sub msg
main : Program () String String
main =
Platform.worker
{ init = \() -> ( "", Cmd.none )
, update = \_ s -> ( s, b_outgoing s )
, subscriptions = \_ -> b_incoming identity
}
Let’s compile them together into the same JavaScript file:
elm make src/A.elm src/B.elm --output combined.js
Then let’s initialize both:
const appA = Elm.A.init();
const appB = Elm.A.init();
console.log("A ports", appA.ports);
console.log("B ports", appB.ports);
Both logs show 4 ports available: a_outgoing, a_incoming, b_outgoing, b_incoming
I would have expected:
appA: a_outgoing, a_incoming
appB: b_outgoing, b_incoming
If you do appA.b_outgoing.subscribe(console.log) nothing is ever logged, and if you do appA.b_incoming.send("") nothing ever gets to A and not to B either. So the extra ports are harmless, they’re just confusing.
Here are two minimal Elm programs, that both use ports with different names:
Let’s compile them together into the same JavaScript file:
Then let’s initialize both:
Both logs show 4 ports available:
a_outgoing,a_incoming,b_outgoing,b_incomingI would have expected:
appA:a_outgoing,a_incomingappB:b_outgoing,b_incomingIf you do
appA.b_outgoing.subscribe(console.log)nothing is ever logged, and if you doappA.b_incoming.send("")nothing ever gets to A and not to B either. So the extra ports are harmless, they’re just confusing.