start :: forall state action eff. Config state action eff -> Eff (CoreEffects eff) (App state action)
Start an application. The resulting html signal is fed into renderToDOM
.
main = do
app <- start
{ update: update
, view: view
, initialState: initialState
, inputs: [] }
renderToDOM "#app" app.html
type Config state action eff = { update :: Update state action eff, view :: state -> Html action, initialState :: state, inputs :: Array (Signal action) }
The configuration of an app consists of update and view functions along with an initial state.
The update
and view
functions describe how to step the state and view
the state.
The inputs
array is for any external signals you might need. These will
be merged into the app's input signal.
type CoreEffects eff = (channel :: CHANNEL, err :: EXCEPTION | eff)
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 State Action)
main state = do
-- ...
type App state action = { html :: Signal (Html action), state :: Signal state, actionChannel :: Channel (List action) }
An App
consists of three signals:
-
html
– A signal ofHtml
representing the current view of your app. This should be fed intorenderToDOM
. -
state
– A signal representing the application's current state.
type Update state action eff = action -> state -> EffModel state action eff
Synonym for an update function that returns state and an array of asynchronous effects that return an action.
type EffModel state action eff = { state :: state, effects :: Array (Aff (CoreEffects eff) action) }
EffModel
is a container for state and a collection of asynchronous
effects which return an action.
fromSimple :: forall s a eff. (a -> s -> s) -> Update s a eff
Create an Update
function from a simple step function.
noEffects :: forall state action eff. state -> EffModel state action eff
Create an EffModel
with no effects from a given state.
onlyEffects :: forall state action eff. state -> Array (Aff (CoreEffects eff) action) -> EffModel state action eff
mapState :: forall sa sb a e. (sa -> sb) -> EffModel sa a e -> EffModel sb a e
Map over the state of an EffModel
.
mapEffects :: forall s a b e. (a -> b) -> EffModel s a e -> EffModel s b e
Map over the effectful actions of an EffModel
.
renderToDOM :: forall a eff. String -> Signal (Html a) -> Eff eff Unit
renderToString :: forall a eff. Signal (Html a) -> Eff eff String
toReact :: forall a props eff. Signal (Html a) -> Eff eff (ReactClass props)
Return a ReactClass from a Pux component's html signal.