elm-lang/core/5.0.0

NOTE: this package moved to elm/core

NOTE: this package is not compatible with Elm 0.19.1

Platform

Programs

type Program flags model msg

A Program describes how to manage your Elm app.

You can create headless programs with the program and programWithFlags functions. Similar functions exist in Html.App that let you specify a view.

Honestly, it is totally normal if this seems crazy at first. The best way to understand is to work through guide.elm-lang.org. It makes way more sense in context!

{ init : ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
}
-> Program Never model msg

Create a headless program. This is great if you want to use Elm as the “brain” for something else. You can still communicate with JS via ports and manage your model, you just do not have to specify a view.

Initializing a headless program from JavaScript looks like this:

var app = Elm.MyThing.worker();
{ init : flags -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
}
-> Program flags model msg

Same as program, but you can provide flags. Initializing a headless program (with flags) from JavaScript looks like this:

var app = Elm.MyThing.worker({ user: 'Tom', token: 1234 });

Whatever argument you provide to worker will get converted to an Elm value, allowing you to configure your Elm program however you want from JavaScript!

Platform Internals

Tasks and Processes

type Task err ok

Head over to the documentation for the Task module for more information on this. It is only defined here because it is a platform primitive.

Head over to the documentation for the Process module for information on this. It is only defined here because it is a platform primitive.

Effect Manager Helpers

An extremely tiny portion of library authors should ever write effect managers. Fundamentally, Elm needs maybe 10 of them total. I get that people are smart, curious, etc. but that is not a substitute for a legitimate reason to make an effect manager. Do you have an organic need this fills? Or are you just curious? Public discussions of your explorations should be framed accordingly.

type Router appMsg selfMsg

An effect manager has access to a “router” that routes messages between the main app and your individual effect manager.

sendToApp : Router msg a -> msg -> Task x ()

Send the router a message for the main loop of your app. This message will be handled by the overall update function, just like events from Html.

sendToSelf : Router a msg -> msg -> Task x ()

Send the router a message for your effect manager. This message will be routed to the onSelfMsg function, where you can update the state of your effect manager as necessary.

As an example, the effect manager for web sockets