Platform

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 that let you specify a view.

program : 
  { 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();


programWithFlags :  
  { 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.

type ProcessId
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

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.