Skip to content

Latest commit

 

History

History
143 lines (94 loc) · 3.24 KB

Pux.md

File metadata and controls

143 lines (94 loc) · 3.24 KB

Module Pux

start

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

Config

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.

CoreEffects

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

App

type App state action = { html :: Signal (Html action), state :: Signal state, actionChannel :: Channel (List action) }

An App consists of three signals:

  • html – A signal of Html representing the current view of your app. This should be fed into renderToDOM.

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

Update

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.

EffModel

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

fromSimple :: forall s a eff. (a -> s -> s) -> Update s a eff

Create an Update function from a simple step function.

noEffects

noEffects :: forall state action eff. state -> EffModel state action eff

Create an EffModel with no effects from a given state.

onlyEffects

onlyEffects :: forall state action eff. state -> Array (Aff (CoreEffects eff) action) -> EffModel state action eff

mapState

mapState :: forall sa sb a e. (sa -> sb) -> EffModel sa a e -> EffModel sb a e

Map over the state of an EffModel.

mapEffects

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

renderToDOM :: forall a eff. String -> Signal (Html a) -> Eff eff Unit

renderToString

renderToString :: forall a eff. Signal (Html a) -> Eff eff String

toReact

toReact :: forall a props eff. Signal (Html a) -> Eff eff (ReactClass props)

Return a ReactClass from a Pux component's html signal.