Module

Spork.PureApp

Package
purescript-spork
Repository
natefaubion/purescript-spork

#PureApp Source

type PureApp model action = { init :: model, render :: model -> Html action, update :: model -> action -> model }

A PureApp has no effects or subscriptions.

#make Source

make :: forall action model eff. PureApp model action -> Node -> Eff (AppEffects eff) (AppInstance (AppEffects eff) model action)

Builds a running PureApp.

example domNode = do
  inst <- PureApp.make app domNode
  _    <- inst.subscribe \_ -> log "Got a change!"

#makeWithSelector Source

makeWithSelector :: forall action model eff. PureApp model action -> String -> Eff (AppEffects eff) (AppInstance (AppEffects eff) model action)

Builds a running PureApp given a DOM selector.

main = do
  inst <- PureApp.makeWithSelector app "#app"
  _    <- inst.subscribe \_ -> log "Got a change!"

#toApp Source

toApp :: forall void2 void1 action model. PureApp model action -> App void1 void2 model action

Converts a PureApp to a regular App.

Re-exports from Spork.App

#AppInstance Source

type AppInstance eff model action = { push :: action -> Eff eff Unit, restore :: model -> Eff eff Unit, run :: Eff eff Unit, snapshot :: Eff eff model, subscribe :: (AppChange model action -> Eff eff Unit) -> Eff eff (Eff eff Unit) }

The interface for communicating with a running App.

  • push - Buffers an action to be run on the next tick.
  • run - Initiates a tick of the App, flushing and applying all queued actions.
  • snapshot - Yields the current model of the App.
  • restore - Replaces the current model of the App.
  • subscribe - Listens to App changes (model and actions).

#AppEffects Source

type AppEffects eff = (dom :: DOM, exception :: EXCEPTION, ref :: REF | eff)

#AppChange Source

type AppChange model action = { action :: action, new :: model, old :: model }

#App Source

type App effects subs model action = { init :: Transition effects model action, render :: model -> Html action, subs :: model -> Batch subs action, update :: model -> action -> Transition effects model action }

A specification for a Spork app:

  • render - Renders a model to Html which yields actions via DOM events.
  • update - Takes the current model and, with a new action, transitions to a new model while optionally running effects.
  • subs - Determines the set of active subscriptions based on the model.
  • init - Initial model and effects to kickstart the application.