A symmetrical simplified Elm lifecycle diagram.
Below is a simplified description of events just to help follow along the above diagram. For more detailed descriptions of Elm workflow please see one of the following resources:
An HTML.App.program
is created within the main
function of an Elm program. The Html.App.program
initiates the Elm application by calling your init
function. This creates a (Model, Cmd Msg)
tuple which is handed off to the Elm runtime.
main
is calledHtml.App.program
is called withinmain
Html.App.program
calls yourinit
function- The
init
function returns a(Model, Cmd Msg)
tuple which is handed off to the Elm runtime - The Elm runtime runs the
Cmd
and then calls yourupdate
function with the resultantMsg
andModel
(thus closing the "update loop") update
then returns a new(Model, Cmd Msg)
tuple- the update loop may continue until no more
Cmd
s are run
Once the Elm program has been initialized and a view is rendered to the screen then further updates come from either subscription to external events such as time, or a web socket; or from user interaction with the view.
- an external event occurs to which your application is subscribed
- the
subscriptions
function passes aSub Msg
to the Elm runtime TheMsg
will most likely contain a payload from the event. - the Elm runtime passes the
Msg
(with its payload) and the currentModel
to yourupdate
function (thus beginning the update loop)
- the user interacts with the view (clicks a button, mouseover a div etc)
- if an
Html.Events
event has been configured for the user behavior, then anHtml Msg
is passed to the Elm runtime. - the Elm runtime passes the
Msg
(with its payload) and the currentModel
to yourupdate
function (thus beginning the update loop)