Bonsai.Types
- Package
- purescript-bonsai
- Repository
- grmble/purescript-bonsai
This module defines the central Bonsai types that are used in the Core and VirtualDom modules.
#BrowserEvent Source
type BrowserEvent msg = F msg
A BrowserEvent is simply a decoded foreign
This is inherently composable - it's a full monad.
#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
#CmdDecoder Source
type CmdDecoder aff msg = Foreign -> Either Error (Cmd aff msg)
And finally, a Command Decoder turns a foreign into a command
The CmdDecoder will be implemented using EventDecoders internally.
#Emitter Source
type Emitter aff msg = Either Error (Cmd aff msg) -> Eff aff Boolean
Emitters will get the Cmd into the Bonsai event loop.
The javascript side has little knowlege about the internal structure of the purescript types, so an emitting function is provided that takes care of all that.
On error, the emitter returns true to signal to javascript that the originating event should be logged to the console.
#EventDecoder Source
type EventDecoder msg = Foreign -> BrowserEvent msg
A EventDecoder decodes a foreign to a BrowserEvent
#TaskContext Source
type TaskContext eff msg = { document :: Document, emitter :: msg -> Eff eff Unit, fiber :: AVar (Fiber eff Unit) }
The Task Context holds the emitter function for the task
Maybe: a way to get at the current model? That would mean the model has to encoded in all the view functions as well. Maybe not a good idea.
#emptyCommand Source
emptyCommand :: forall msg aff. Cmd aff msg
Produces an empty command.
#pureCommand Source
pureCommand :: forall msg aff. msg -> Cmd aff msg
Produces a pure command