Module

Solid.Reactivity

Package
purescript-purs-solid
Repository
arazorda/purs-solid

Memos, effects and scheduling. Effects have a tracked, pure compute phase (an Accessor) and an untracked apply phase (a -> Effect ...) whose cleanup runs before the next apply and on disposal.

#MemoOptions Source

type MemoOptions :: Type -> Row Typetype MemoOptions a = (equals :: Equality a, id :: String, lazy :: Boolean, name :: String, transparent :: Boolean, unobserved :: Effect Unit)

#createMemo Source

createMemo :: forall f a. Tracked f => f a -> Setup (f a)

Caches a derived accessor: it recomputes only when its dependencies change, and notifies only when the result changes.

#createMemoWith Source

createMemoWith :: forall f a given missing. Tracked f => Union given missing (MemoOptions a) => Record given -> f a -> Setup (f a)

Takes any subset of MemoOptions.

#createWritableMemo Source

createWritableMemo :: forall a. Accessor a -> Setup (Signal a)

A signal derived from compute that can also be written locally. A write wins until a dependency of compute changes, which re-derives it.

#createWritableMemoWith Source

createWritableMemoWith :: forall a given missing. Union given missing (MemoOptions a) => Record given -> Accessor a -> Setup (Signal a)

Takes any subset of MemoOptions.

#EffectOptions Source

type EffectOptions :: Row Typetype EffectOptions = (defer :: Boolean, name :: String, onError :: Error -> Effect Unit, schedule :: Boolean, transparent :: Boolean)

#createEffect Source

createEffect :: forall f a. Tracked f => f a -> (a -> Effect (Effect Unit)) -> Setup Unit

Runs apply with the value of compute now (after the current flush) and whenever it changes. The Effect Unit that apply returns is its cleanup.

#createEffect_ Source

createEffect_ :: forall f a. Tracked f => f a -> (a -> Effect Unit) -> Setup Unit

#createEffectWith Source

createEffectWith :: forall f a given missing. Tracked f => Union given missing EffectOptions => Record given -> f a -> (a -> Effect (Effect Unit)) -> Setup Unit

Takes any subset of EffectOptions.

#createRenderEffect Source

createRenderEffect :: forall f a. Tracked f => f a -> (a -> Effect (Effect Unit)) -> Setup Unit

Like createEffect, but the apply phase runs synchronously during rendering, before the DOM is committed.

#createRenderEffect_ Source

createRenderEffect_ :: forall f a. Tracked f => f a -> (a -> Effect Unit) -> Setup Unit

#Reaction Source

data Reaction

A reaction runs its handler once, the next time anything read by the last track changes.

#track Source

track :: forall f a. Tracked f => Reaction -> f a -> Effect Unit

Reads accessor under the reaction, recording its dependencies.

#flush Source

flush :: Effect Unit

Applies pending writes now instead of at the next microtask.

#withFlush Source

withFlush :: forall a. Effect a -> Effect a

Runs action and applies the writes it made before returning.