elmelm-architecture

How to handle multiple subscriptions in the elm architecture


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?


Solution

  • You may use Sub.batch, providing a list of subscriptions, it returns a batched subscription

    Reference: