Platform

This module contains definitions important to the language runtime. You're unlikely to make direct use of these things yourself.

type Program flags model msg

A Program describes an Gren program! How does it react to input? Does it show anything on screen? Etc.

worker :
{ init : flags -> { model : model, command : Cmd msg }
, update : msg -> model -> { model : model, command : Cmd msg }
, subscriptions : model -> Sub msg
}
-> Program flags model msg

Create a headless program with no user interface.

This is great if you want to use Gren as the “brain” for something else. For example, you could send messages out ports to modify the DOM, but do all the complex logic in Gren.

Initializing a headless program from JavaScript looks like this:

var app = Gren.MyThing.init();

If you do want to control the user interface in Gren, the Browser module has a few ways to create that kind of Program instead!

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

Effect managers can be viewed as programs-within-a-program. They have their own state, and communicate with the application using messages.

Effect managers are used internally for many things, but isn't considered to be truly stable. It's likely that this feature will be redesigned in a future relase.

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