Module

Solid.Store

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

Stores: nested reactive state. Records and arrays are tracked per field and element; every other type is atomic, stored as-is and replaced as a whole.

Store.update setState $ Store.at (key @"todos") (Store.push todo)

#StoreSetter Source

data StoreSetter t0

#StoreObject Source

class StoreObject a 

Instances

#createStore Source

createStore :: forall m s. MonadReactive m => StoreObject s => StoreValue s => s -> m ((Store s) /\ (StoreSetter s))

Works in Effect or Setup (stores need no owner). The initial value is never mutated.

#Path Source

newtype Path s a

A path to a field, built from record labels with key and composed with >>>.

Instances

#key Source

key :: forall @l r a tail. IsSymbol l => Cons l a tail r => Path (Record r) a

#StoreCursor Source

class StoreCursor :: (Type -> Type) -> (Type -> Type) -> Constraintclass (Tracked f) <= StoreCursor store f | store -> f

Store and AsyncStore cursors, and what reading them gives: an AsyncStore may not have its first value yet, so its values are Async.

Instances

#focus Source

focus :: forall store f s a. StoreCursor store f => Path s a -> store s -> store a

#focusKey Source

focusKey :: forall @l store f r a tail. StoreCursor store f => IsSymbol l => Cons l a tail r => store (Record r) -> store a

focusKey @"todos" store is focus (key @"todos") store.

#atKey Source

atKey :: forall @l r a tail. IsSymbol l => Cons l a tail r => Update a -> Update (Record r)

atKey @"todos" change is at (key @"todos") change.

#value Source

value :: forall store f a. StoreCursor store f => store a -> f a

Tracks the whole focused part; focus first to track less.

#items Source

items :: forall store f a. StoreCursor store f => StoreObject a => store (Array a) -> f (Array (store a))

A cursor per element. Cursors keep their identity while an element stays in the array, so keyed list rendering reuses rows.

#snapshot Source

snapshot :: forall a. Store a -> Effect a

An untracked copy of the current value. Not for an AsyncStore, which may not have one yet.

#Update Source

data Update t0

A pure description of changes. Combine with <>; they apply in order, in one batch.

Instances

#update Source

update :: forall s. StoreSetter s -> Update s -> Effect Unit

Applies an update. Readers see it after the next flush.

#at Source

at :: forall s a. Path s a -> Update a -> Update s

#set Source

set :: forall a. StoreValue a => a -> Update a

#modify Source

modify :: forall a. StoreValue a => (a -> a) -> Update a

#push Source

push :: forall a. StoreValue a => a -> Update (Array a)

#filter Source

filter :: forall a. (a -> Boolean) -> Update (Array a)

Removes failing elements in place; kept elements keep their identity and readers.

#atIndex Source

atIndex :: forall a. Int -> Update a -> Update (Array a)

Does nothing if the index is out of range.

#each Source

each :: forall a. Update a -> Update (Array a)

#eachWhere Source

eachWhere :: forall a. (a -> Boolean) -> Update a -> Update (Array a)

#reconcile Source

reconcile :: forall a. StoreValue a => a -> Update a

Replaces the value with next, keeping everything that didn't change (and its readers). Array elements are matched by their id field.

#reconcileBy Source

reconcileBy :: forall a k. StoreValue a => (a -> k) -> Array a -> Update (Array a)

reconcile for an array, matching elements by a key function. Keys are compared with ===, so use primitives.

#reconcileByPosition Source

reconcileByPosition :: forall a. StoreValue a => Array a -> Update (Array a)

reconcile for an array, matching elements by position.

#createProjection Source

createProjection :: forall s. StoreObject s => StoreValue s => Accessor (Update s) -> s -> Setup (Store s)

A read-only store derived from reactive sources: compute is tracked and yields the update to apply whenever its dependencies change.

#createProjectionAsync Source

createProjectionAsync :: forall s. StoreObject s => StoreValue s => Accessor (Aff (Update s)) -> s -> Setup ((AsyncStore s) /\ (Refresh s))

Like createProjection, but the update comes from async work: readers suspend (show loading fallbacks) until the first update, and a change of compute's dependencies kills the running Aff. Refresh re-runs it.

#createDerivedStore Source

createDerivedStore :: forall s. StoreObject s => StoreValue s => Accessor (Update s) -> s -> Setup ((Store s) /\ (StoreSetter s))

A store derived like createProjection that can also be updated locally; a local update holds until compute's dependencies change.

#createSelector Source

createSelector :: forall f a. Tracked f => (a -> String) -> f a -> Setup (a -> Accessor Boolean)

isSelected x is true when source equals x (compared by toKey). A selection change notifies only the two affected readers.

#OptimisticStore Source

data OptimisticStore t0

Updated only from a Solid.Action.Action; its updates show immediately and revert when the action settles.

#createOptimisticStore Source

createOptimisticStore :: forall m s. MonadReactive m => StoreObject s => StoreValue s => s -> m ((Store s) /\ (OptimisticStore s))

A store whose updates are tentative: made during an action, reverted when it settles.

#createOptimisticProjection Source

createOptimisticProjection :: forall s. StoreObject s => StoreValue s => Accessor (Update s) -> s -> Setup ((Store s) /\ (OptimisticStore s))

Follows compute like createProjection, with tentative updates layered on top during actions.

#updateOptimistic Source

updateOptimistic :: forall m s. MonadOptimistic m => OptimisticStore s -> Update s -> m Unit

A tentative update, as a step of a Solid.Action.Action.

#affects Source

affects :: forall m store f s. MonadOptimistic m => StoreCursor store f => StoreObject s => store s -> m Unit

Marks the focused part of a store as pending until the action settles.

Re-exports from Solid.Internal.Optimistic

#MonadOptimistic Source

class MonadOptimistic :: (Type -> Type) -> Constraintclass (Monad m) <= MonadOptimistic m 

Re-exports from Solid.Internal.Store

#Store Source

data Store t0

A read-only cursor into a store, focused on a value of type a.

#AsyncStore Source

data AsyncStore t0

A cursor into a store that may not have its first value yet (an async projection): reading it gives Async values.

#StoreFields Source

#StoreValue Source

class StoreValue a 

How a type is stored: records and arrays are tracked per field / element; anything else is atomic. Every type has an instance. preparer is a value, so it's built once per type.

Instances