Module

Bonsai

Package
purescript-bonsai
Repository
grmble/purescript-bonsai

Bonsai main module for imports

View code will also want Bonsai.Html and Bonsai.Event

Re-exports from Bonsai.Core

#UpdateResult Source

type UpdateResult aff model msg = { cmd :: Cmd aff msg, model :: model }

An update functions returns a new model and a possibly empty command

#ProgramState Source

type ProgramState model msg = { dirty :: Boolean, dnode :: Element, model :: model, vnode :: VNode msg }

ProgramState tracks the current state of the model, vnode and dom element.

These are needed to advance the state in reaction to a Cmd message.

#Program Source

type Program aff model msg = { dbgEvents :: Boolean, dbgTiming :: Boolean, document :: Document, pending :: Ref (Array msg), renderer :: model -> VNode msg, state :: Ref (ProgramState model msg), updater :: model -> msg -> UpdateResult aff model msg, window :: Window }

Program describes the Bonsai program.

It is passed around in a ReaderT and stores callbacks and a ref to the pending commands. Event callbacks append to the list of pending commands, they will then be applied in the main event loop.

#simpleTask Source

simpleTask :: forall aff msg. Aff aff msg -> Cmd aff msg

Produces a simple task (not cancellable, ony emits the return values

#program Source

program :: forall eff aff model msg. ElementId -> (model -> msg -> UpdateResult aff model msg) -> (model -> VNode msg) -> model -> Window -> Eff (bonsai :: BONSAI, exception :: EXCEPTION | eff) (Program aff model msg)

Create initial environment for the Bonsai program.

#plainResult Source

plainResult :: forall aff model msg. model -> UpdateResult aff model msg

Creates an update result with empty command.

#mapResult Source

mapResult :: forall aff model1 msg1 model2 msg2. (model1 -> model2) -> (msg1 -> msg2) -> UpdateResult aff model1 msg1 -> UpdateResult aff model2 msg2

Helper to map update results from sub-components

#issueCommand Source

issueCommand :: forall bff eff model msg. Program bff model msg -> Cmd bff msg -> Eff (bonsai :: BONSAI | eff) Unit

Issue a command.

For pure commands, this will send the messages and request a redraw. For (asynchronous) task commands, the task will be started.

This can be used to start tasks, e.g. to initialize the model

#emittingTask Source

emittingTask :: forall aff msg. (TaskContext aff msg -> Aff aff Unit) -> Cmd aff msg

Procudes a task that can emit multiple times

#emitMessage Source

emitMessage :: forall aff msg. TaskContext aff msg -> msg -> Aff aff Unit

Emit helper for Tasks.

In an emitting task, use this function to emit messages.

#debugProgram Source

debugProgram :: forall eff aff model msg. ElementId -> (model -> msg -> UpdateResult aff model msg) -> (model -> VNode msg) -> model -> Boolean -> Boolean -> Window -> Eff (bonsai :: BONSAI, exception :: EXCEPTION | eff) (Program aff model msg)

Re-exports from Bonsai.DOM

#ElementId Source

newtype ElementId

The ID of an element in the DOM

Constructors

#Element Source

newtype Element

A DOM Element

#window Source

window :: forall eff. Eff (bonsai :: BONSAI | eff) Window

Get the global javascript Window object

#elementById Source

elementById :: forall eff. ElementId -> Document -> Eff (bonsai :: BONSAI | eff) (Maybe Element)

Get the element identified by id.

#document Source

document :: forall eff. Window -> Eff (bonsai :: BONSAI | eff) Document

Get the global javascript Document object

Re-exports from Bonsai.Types

#Window Source

newtype Window

The type for the global javascript window

#EventDecoder Source

type EventDecoder msg = Foreign -> BrowserEvent msg

A EventDecoder decodes a foreign to a BrowserEvent

#Document Source

newtype Document

The type for the global javascript document

#Cmd Source

data Cmd eff msg

A Command represents messages that should be applied to the Bonsai model

A command is either Pure (the constructor Cmd) or an asynchronous Task. The pure command simply contains the messages that will be emitted. The asynchronous Task gets an emitter function that it can use to emit messages at will.

There is currently no effectful synchronous command - there used to be, but it did not turn out very useful except in dumbed down examples.

There could be a helper function that expresses simple effectful commands as Tasks though.

There used to be a helper type for TaskContext -> Aff but for some reason it did not unify in user code. So the recommendation is to produce the command, not the function with complicated signature that goes inside a TaskCmd.

Constructors

Instances

#BONSAI Source

data BONSAI :: Effect

Effect for public types

#pureCommand Source

pureCommand :: forall aff msg. msg -> Cmd aff msg

Produces a pure command

#emptyCommand Source

emptyCommand :: forall aff msg. Cmd aff msg

Produces an empty command.