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 ofMarkup 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.
#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.
#onlyEffects Source
onlyEffects :: forall fx ev st. st -> Array (Aff (CoreEffects fx) (Maybe ev)) -> EffModel st ev fx
#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
.