I am working through the elm guide.
In the effects subchapter there is an example with a Time-subscription
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every second Tick
and an example which handles Web-Sockets-subscriptions
subscriptions : Model -> Sub Msg
subscriptions model =
WebSocket.listen "ws://echo.websocket.org" NewMessage
But in these examples, there is only ever one subscription. How could I handle multiple subscriptions?
In this section, we'll learn how a subscription works. Subscription is the last piece of the Elm Architecture puzzle. It'll also come handy for receiving data from JavaScript in the next section.
The Elm Architecture is a pattern for architecting interactive programs, like webapps and games. This architecture seems to emerge naturally in Elm. Rather than someone inventing it, early Elm programmers kept discovering the same basic patterns in their code.
You may use Sub.batch
, providing a list of subscriptions, it returns a batched subscription
Reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With