Module

Bonsai.Core

Package
purescript-bonsai
Repository
grmble/purescript-bonsai

#Program Source

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

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.

#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.

#debugProgram Source

debugProgram :: forall msg model aff eff. Element -> Boolean -> Boolean -> (model -> msg -> UpdateResult aff model msg) -> (model -> VNode msg) -> model -> Eff (avar :: AVAR, console :: CONSOLE, dom :: DOM, ref :: REF | eff) (Program aff model msg)

#emitMessages Source

emitMessages :: forall msg aff. TaskContext aff (Array msg) -> Array msg -> Aff aff Unit

Emit helper for Tasks.

#emittingTask Source

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

Procudes a task that can emit multiple times

#mapResult Source

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

Helper to map update results from sub-components

#plainResult Source

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

Creates an update result with empty command.

#program Source

program :: forall msg model aff eff. Element -> (model -> msg -> UpdateResult aff model msg) -> (model -> VNode msg) -> model -> Eff (avar :: AVAR, console :: CONSOLE, dom :: DOM, ref :: REF | eff) (Program aff model msg)

Create initial environment for the Bonsai program.

#simpleTask Source

simpleTask :: forall msg aff. Aff aff (Array msg) -> Cmd aff msg

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

#taskContext Source

taskContext :: forall msg model eff. Program eff model msg -> Aff (avar :: AVAR, console :: CONSOLE, dom :: DOM, ref :: REF | eff) (TaskContext eff (Array msg))

Obtain a task context for a bonsai program.

The task context can be used with emitMessages