Module

Marionette.Controllers.ControlAPI

Package
purescript-marionette
Repository
thought2/purescript-marionette

A Control handler that runs in Aff and provides a beginner friendly API to handle state updates with effects.

#Control Source

type Control msg sta = ControlAPI msg sta -> msg -> Aff Unit

The high level control function. Takes an interface to a control API and a msg and returns an effectful computation inside Aff.

#ControlAPI Source

type ControlAPI msg sta = { getState :: Aff sta, modifyState :: (sta -> sta) -> Aff sta, modifyState_ :: (sta -> sta) -> Aff Unit, putState :: sta -> Aff Unit, sendMsg :: msg -> Aff Unit }

Provides read/write access to the current state and a way to raise new messages at any time in the control handler

  • sendMsg Raise a new message.
  • getState Set the current state.
  • putState Set the state.
  • modifyState Modify the state by applying a function to the current state. The returned value is the new state value.
  • modifyState_ Modify the state by applying a function to the current state.

#mkController Source

mkController :: forall msg sta. Control msg sta -> Controller msg sta

Creates a low level controller when given a high level control function