Module

Pux

Package
purescript-pux
Repository
alexmingoia/purescript-pux

#start Source

start :: forall fx st ev e. Config e ev st fx -> Eff (CoreEffects fx) (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

#Config Source

type Config e ev st fx = { foldp :: FoldP st ev fx, 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.

#CoreEffects Source

type CoreEffects fx = (channel :: CHANNEL, exception :: EXCEPTION | fx)

The set of effects every Pux app needs to allow through when using start. Extend this type with your own app's effects, for example:

type AppEffects = (console :: CONSOLE, dom :: DOM)

main :: State -> Eff (CoreEffects AppEffects) (App DOMEvent State Event)
main state = do
  -- ...

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

#FoldP Source

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

Return an EffModel from the current event and state.

#EffModel Source

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

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

#noEffects Source

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

Create an EffModel with no effects from a given state.

#onlyEffects Source

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

#mapState Source

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

Map over the state of an EffModel.

#mapEffects Source

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

Map over the effects of an EffModel.

#waitEvent Source

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

Wait for a specific event until returning the app state.

#waitState Source

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

Wait for a specific state before returning the app state.