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.
mainis calledHtml.App.programis called withinmainHtml.App.programcalls yourinitfunction- The
initfunction returns a(Model, Cmd Msg)tuple which is handed off to the Elm runtime - The Elm runtime runs the
Cmdand then calls yourupdatefunction with the resultantMsgandModel(thus closing the "update loop") updatethen returns a new(Model, Cmd Msg)tuple- the update loop may continue until no more
Cmds 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
subscriptionsfunction passes aSub Msgto the Elm runtime TheMsgwill most likely contain a payload from the event. - the Elm runtime passes the
Msg(with its payload) and the currentModelto yourupdatefunction (thus beginning the update loop)
- the user interacts with the view (clicks a button, mouseover a div etc)
- if an
Html.Eventsevent has been configured for the user behavior, then anHtml Msgis passed to the Elm runtime. - the Elm runtime passes the
Msg(with its payload) and the currentModelto yourupdatefunction (thus beginning the update loop)