Module

Spork.App

Package
purescript-spork
Repository
natefaubion/purescript-spork

#App Source

type App effects subs model action = { render :: model -> Html action, update :: model -> action -> Transition effects model action, subs :: model -> Batch subs action, init :: 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.

#AppEffects Source

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

#AppInstance Source

type AppInstance eff model action = { push :: action -> Eff eff Unit, run :: Eff eff Unit, snapshot :: Eff eff model, restore :: model -> Eff eff Unit, 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).

#AppChange Source

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

#BasicApp Source

type BasicApp effects model action = App effects (Const Void) model action

A type synonym for Apps which don't have subs.

#make Source

make :: forall eff effects subs model action. Interpreter (Eff (AppEffects eff)) (Coproduct effects subs) action -> App effects subs model action -> Node -> Eff (AppEffects eff) (AppInstance (AppEffects eff) model action)

Builds a running App given an Interpreter and a parent DOM Node.

example domNode = do
  inst <- App.make (basicAff `merge` never) app domNode
  _    <- inst.subscribe \_ -> log "Got a change!"
  inst.run

The returned AppInstance has yet to run any initial effects. You may use the opportunity to setup change handlers. Invoke inst.run when ready to run initial effects.

#makeWithSelector Source

makeWithSelector :: forall eff effects subs model action. Interpreter (Eff (AppEffects eff)) (Coproduct effects subs) action -> App effects subs model action -> String -> Eff (AppEffects eff) (AppInstance (AppEffects eff) model action)

Builds a running App given an Interpreter and a DOM selector.

main = do
  inst <- App.makeWithSelector (basicAff `merge` never) app "#app"
  _    <- inst.subscribe \_ -> log "Got a change!"
  inst.run

The returned AppInstance has yet to run any initial effects. You may use the opportunity to setup change handlers. Invoke inst.run when ready to run initial effects.

Re-exports from Spork.Batch

#Batch Source

newtype Batch f a

A type for Batching effects/subscriptions.

Instances

#unBatch Source

unBatch :: forall f a. Batch f a -> Array (f a)

#lift Source

lift :: forall f a. f a -> Batch f a

Lifts a singleton effect/subscription into Batch.

#batch Source

batch :: forall f a. Array (f a) -> Batch f a

Builds a Batch from an Array.

Re-exports from Spork.Transition

#Transition Source

type Transition m s i = { model :: s, effects :: Batch m i }

#purely Source

purely :: forall f s i. s -> Transition f s i

A pure model Transition without effects.