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();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!
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.
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.
An effect manager has access to a “router” that routes messages between the main app and your individual effect manager.
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.
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
A
Programdescribes how to manage your Elm app.You can create headless programs with the
programandprogramWithFlagsfunctions. Similar functions exist inHtmlthat 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!