Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 585
DanEEStar Avatar asked May 24 '17 21:05

DanEEStar


People also ask

What are subscriptions in Elm?

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.

What is Elm architecture?

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.


1 Answers

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

Reference:

  • Elm 0.19 docs
  • Pre-0.19 docs
like image 167
rstar Avatar answered Oct 04 '22 02:10

rstar