DanEEStar
DanEEStar

Reputation: 6280

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?

Upvotes: 19

Views: 2939

Answers (1)

rstar
rstar

Reputation: 1006

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

Reference:

Upvotes: 29

Related Questions