Node.Program

A NodeJS program is defined like most other Gren programs, except that there is more flexibility regarding how it is initialized.

You can initialize any number of subsystems, like FileSystem or Terminal, before initializing your own program with the results of those initializations.

As part of initializing a subsystem, you usually also get access to a value that permits you to contact said subsystem. Be careful what code you give these permissions to.

Simple Program

type alias SimpleProgram a = Program {} a

A simple program that executes a single task and then exits.

defineSimple : AppInitTask (Cmd a) -> SimpleProgram a

Define a simple program that doesn't require long-lived state or the ability to respond to messages or subscriptions. Ideal for simple and short-lived programs.

endWithCmd : Cmd a -> AppInitTask (Cmd a)

When defining a program with defineTask, use this function to define the final command to execute.

Program

type alias Program model msg = Program {} (Model model) (Msg model msg)

The definition of a Gren program that runs on NodeJS.

type alias ProgramConfiguration model msg =
{ init : AppInitTask { model : model, command : Cmd msg }
, update : msg -> model -> { model : model, command : Cmd msg }
, subscriptions : model -> Sub msg
}

The required functions that define a program.

define : ProgramConfiguration model msg -> Program model msg

Define a program with access to long-lived state and the ability to respond to messages and listen to subscriptions. If you want to define a simple and short-lived program, chances are you're looking for defineSimple instead.

startProgram :
{ model : model
, command : Cmd cmd
}
-> AppInitTask { model : model, command : Cmd cmd
}

This lets the runtime know that you're done initializing other subsystems, and that your program is ready to start.

Initialization

type alias AppInitTask a = AppInitTask a

This is like a Task, but can only be run as part of initializing your program. This is usually used for values which should be provided to your program, and only your program, as opposed to third-party packages.

await : AppInitTask a -> (a -> AppInitTask b) -> AppInitTask b

This let's you wait for the completion of an AppInitTask before either starting your application, or begin initialization of another AppInitTask.

Program.await Node.initialize <| \nodeConfig ->
Program.await FileSystem.initialize <| \fileSystemConfig ->
    -- Start your own program with the values from Node and FileSystem
    Program.startProgram
        { model = 1
        , commands = Cmd.none
        }
awaitTask : Task Never a -> (a -> AppInitTask b) -> AppInitTask b

This let's you wait for the completion of a Task before either starting your application, or begin initialization of another AppInitTask.

Program.await Node.initialize <| \nodeConfig ->
Program.awaitTask Task.now <| \time ->
    -- Start your own program with the values from Node and FileSystem
    Program.startProgram
        { model = time
        , commands = Cmd.none
        }