#REDUX Source

data REDUX :: Effect

Effect for actions that modify a redux store

#Action Source

type Action r = { type :: String | r }

The type of redux actions.

An action is a record containing at least a "type" field

increment :: Int -> Action (value :: Int)
increment value = { type: "INCREMENT", value }

#Reducer Source

type Reducer s r = s -> Action r -> s

The type of a redux reducer

A reducer is a function that takes a state and an action, and returns a new state based on that action.

reducer :: Reducer Int (value :: Int)
reducer state action =
  case action.type of
    "INCREMENT" -> state + action.value
    _ -> state

#Dispatch Source

type Dispatch r fx = Action r -> Eff (CoreEffects (redux :: REDUX | fx)) Unit

The type of redux's dispatch function

A dispatch function takes an action as an argument and returns an effectul computation that modifies the redux store, and has some other unknown effects.

  :: forall fx ev st
   . Dispatch (value :: Int) fx
  -> FoldP st ev (redux :: REDUX | fx)
foldp dispatch ev st =
  case ev of
    ... ->
      { state: ...
      , effects:
        [ ...
        , liftEff (dispatch $ increment 5) $> Nothing

#initialDispatch Source

initialDispatch :: forall fx r. Dispatch r fx

A safe initial value for the dispatch function. This will normally be used from Javascript.

#AppState Source

type AppState payload st fx = { dispatch :: Dispatch payload fx | st }

The state type for apps that have access to a dispatch function.

You will never have to create a value of this type manually.

#AppEvent Source

data AppEvent pl fx ev

The event type for apps that have access to a dispatch function

You will never have to create a value of this type manually.


#appEvent Source

appEvent :: (forall ev. (DOMEvent -> ev) -> EventHandlers (DOMEvent -> ev)) -> (forall fx pl event. (DOMEvent -> event) -> EventHandlers (DOMEvent -> AppEvent pl fx event))

Lift an event source from supplying events to supplying AppEvent pl fx events

textInput :: forall ev pl fx. (String -> ev) -> HTML (AppEvent pl fx ev)
textInput event =
  ! type' "text"
  #! appEvent onChange (event <<< targetValue)

#AppConfig Source

type AppConfig props pl fx ev = { dispatch :: Signal (Dispatch pl fx), foldp :: Dispatch pl fx -> FoldP (Record props) ev (redux :: REDUX | fx), initialState :: Record props, inputs :: Array (Signal ev), view :: Record props -> HTML (AppEvent pl fx ev) }

The configuration of a pux app that can interact with a redux store.

Use 'fromAppConfig' to obtain a regular 'Config'

#fromAppConfig Source

fromAppConfig :: forall props ev fx pl. AppConfig props pl fx ev -> Config (DOMEvent -> AppEvent pl fx ev) (AppEvent pl fx ev) (AppState pl props fx) (redux :: REDUX | fx)

Convert an 'AppConfig' to a 'Config'

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