Module

Pux

Package
purescript-pux
Repository
alexmingoia/purescript-pux

#App Source

type App e ev st = { events :: Signal (List ev), input :: Channel (List ev), markup :: Signal (Markup e), state :: Signal st }

An App is a record consisting of:

  • markup – A signal of Markup e representing the current view of the app. This is consumed by renderers.

  • state – A signal representing the application's current state.

  • input – A channel representing the application's event input.

#Config Source

type Config e ev st = { foldp :: FoldP st ev, initialState :: st, inputs :: Array (Signal ev), view :: st -> Markup e }

The configuration of an app consists of foldp and view functions along with an initial state. The foldp and view functions describe how to step the state and view | the state.

The inputs array is for any external inputs you might need. These will be merged into the app's input signal.

#FoldP Source

type FoldP st ev = ev -> st -> EffModel st ev

Return an EffModel from the current event and state.

#EffModel Source

type EffModel st ev = { effects :: Array (Aff (Maybe ev)), state :: st }

EffModel is a container for state and asynchronous effects which return an event.

#noEffects Source

noEffects :: forall ev st. st -> EffModel st ev

Create an EffModel with no effects from a given state.

#onlyEffects Source

onlyEffects :: forall ev st. st -> Array (Aff (Maybe ev)) -> EffModel st ev

#mapState Source

mapState :: forall ev b a. (a -> b) -> EffModel a ev -> EffModel b ev

Map over the state of an EffModel.

#mapEffects Source

mapEffects :: forall st b a. (a -> b) -> EffModel st a -> EffModel st b

Map over the effects of an EffModel.

#start Source

start :: forall st ev e. Config e ev st -> Effect (App e ev st)

Create an application, which exposes a markup signal that can be used by renderers.

main = do
  app <- start
   { initialState
   , view
   , foldp
   , inputs: [] }

  renderToDOM "#app" app.markup app.input

#waitEvent Source

waitEvent :: forall st ev e. (ev -> Boolean) -> App e ev st -> Aff st

Wait for a specific event until returning the app state.

#waitState Source

waitState :: forall st ev e. (st -> Boolean) -> App e ev st -> Aff st

Wait for a specific state before returning the app state.