updates functions

65 views
Skip to first unread message

Pablo Fernandez

unread,
Jul 12, 2016, 8:58:06 AM7/12/16
to Elm Discuss
Hi guys,

If I have several components that they have its update functions and actions (Msg), How I can manage them from a single place?, I guess that I need a single update in main file and from here call all updates functions.

Per example, if I have this:

type Msg = NoOp | Move Int | SuccessMove Model | FailMove Http.Error

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    Move cardinal ->
      (model, getNewPositions cardinal) -- Getnewsposition return info for the movement
    NoOp ->
      (model, Cmd.none)
    SuccessMove newModel ->
      -- TODO
    FailMove error ->
      (model, Cmd.none)

--------------------------------------------------
and in the main file I have this:

type Msg =
  NoOp
  | GoTo Int

update : Msg -> Model -> (Model, Cmd.Msg)
update msg model =
  case msg of
    NoOp ->
      (model, Cmd.none)
    GoTo a ->
      let
        model' =
          -- How can I call the update from file here? (the type 'a' is the cardinal)
      in
        (model', Cmd.none)


In summary, I need a way to manage other updates from a main update.


Greetings!

Peter Damoc

unread,
Jul 12, 2016, 9:00:35 AM7/12/16
to Elm Discuss
Hi Pablo, 

Have you read the Modularity chapter of the Guide?
http://guide.elm-lang.org/architecture/modularity/counter_pair.html



--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

Pablo Fernandez

unread,
Jul 12, 2016, 11:00:18 AM7/12/16
to Elm Discuss
Thanks Peter, this is what I needed!

You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/km_AitUsc74/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages