Module

Impulse.DOM.Util

Package
purescript-impulse
Repository
mitchdzugan/purescript-impulse

#getEnv Source

getEnv :: forall l r2 r1 a c. IsSymbol l => Cons l a r1 r2 => SProxy l -> DOM (Record r2) c a

getEnv p

pulls the value at p out of the current environment

  p_test = (SProxy :: SProxy "test")

  displayFromEnv :: forall e c. DOM { test :: String | e } c Unit
  displayFromEnv = do
    test <- getEnv p_test    --  <-- Usage here
    div_ anil $ text test

  test :: forall e c. DOM e c Unit
  test = do
    upsertEnv p_test "Hello World!" do
      displayFromEnv

results in

  <div>Hello World!</div>

#withEnv Source

withEnv :: forall a e r2 r1. r2 -> DOM r2 e a -> DOM r1 e a

#upsertEnv Source

upsertEnv :: forall c rOSymless rO rSym rI sym a res. IsSymbol sym => Lacks sym () => Cons sym a () rSym => Cons sym a rOSymless rO => Union rSym rI rO => SProxy sym -> a -> DOM (Record rO) c res -> DOM (Record rI) c res

upsertEnv p value inner

runs inner with value added to the environment at p

  p_test = (SProxy :: SProxy "test")

  displayFromEnv :: forall e c. DOM { test :: String | e } c Unit
  displayFromEnv = do
    test <- getEnv p_test
    div_ anil $ text test

  test :: forall e c. DOM e c Unit
  test = do
    upsertEnv p_test "Hello World!" do     --  <-- Usage here
      displayFromEnv

results in

  <div>Hello World!</div>

#e_collectAndReduce Source

e_collectAndReduce :: forall cOSymless cO cSym cI eOSymless eO eSym eI sym b a res. IsSymbol sym => Lacks sym () => Cons sym (Collector a) () cSym => Cons sym (Collector a) cOSymless cO => Union cSym cI cO => Cons sym (Signal b) () eSym => Cons sym (Signal b) eOSymless eO => Union eSym eI eO => SProxy sym -> (b -> a -> b) -> b -> DOM (Record eO) (Record cO) res -> DOM (Record eI) (Record cI) res

e_collectAndReduce p reducer init inner

Creates a signal from the supplied reducer and initial value. inner is then run with the created signal injected into the environment at p. The event used to drive the reducer is the combination of all events e_emited to p while running inner.

   p_score = (SProxy :: SProxy "score")

   scoreButton ::
     forall e c.
     Int ->
     String ->
     DOM e { score :: Collector Int | c } Unit
   scoreButton change message = do
     d_button <- button anil $ text message
     e_emit p_score $ onClick d_button <#> const change

   displayScore ::
     forall e c.
     DOM { score :: Signal Int | e } c Unit
   displayScore = do
     s_score <- getEnv p_score
     s_bindDOM_ s_score \score -> do
       span_ anil $ text $ "Score: " <> show score

   test :: forall e c. DOM e c Unit
   test = do
     e_collectAndReduce p_score (\agg change -> agg + change) 0 do
       scoreButton (-1) "Decrement Score"
       displayScore
       scoreButton (1) "Increment Score"

results in

  <button>Decrement Score</button>
  <span>Score: 0</span>
  <button>Increment Score</button>

with the score text changing as expected

#d_clone Source

d_clone :: forall a c e. ImpulseStash a -> DOM e c (ImpulseStash a)

#s_extract Source

s_extract :: forall a c e. Signal (ImpulseStash a) -> DOM e c (ImpulseStash (Signal a))

#s_extract_ Source

s_extract_ :: forall a c e. Signal (ImpulseStash a) -> DOM e c (ImpulseStash Unit)

#d_read Source

d_read :: forall res a c e' e sym. IsSymbol sym => Cons sym a e' e => SProxy sym -> Reader a res -> DOM (Record e) (Record c) res

#d_readAs Source

d_readAs :: forall res b a c e' e sym. IsSymbol sym => Cons sym a e' e => SProxy sym -> (a -> b) -> Reader b res -> DOM (Record e) (Record c) res

#s_bindKeyedDOM Source

s_bindKeyedDOM :: forall b a c e. Show a => Signal a -> (a -> DOM e c b) -> DOM e c (Signal b)

#s_bindKeyedDOM_ Source

s_bindKeyedDOM_ :: forall b a c e. Show a => Signal a -> (a -> DOM e c b) -> DOM e c Unit