Redox
- Package
- purescript-redox
- Repository
- coot/purescript-redox
Re-exports from Redox.Free
#dispatchP Source
dispatchP :: forall e eff dsl state. (Error -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) Unit) -> Interp dsl state (redox :: RedoxStore (read :: ReadRedox | e) | eff) -> Store state -> Free dsl (state -> state) -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) (Canceler (redox :: RedoxStore (read :: ReadRedox | e) | eff))
Dispatch function which does not handle store updates. That's useful if
the interpreter is updating the store. You can use
Redox.Utils.mkIncInterp
and Redox.Utils.runSubscriptions
to create
such an interpreter.
#dispatch Source
dispatch :: forall e eff dsl state. (Error -> Eff (redox :: RedoxStore (read :: ReadRedox, write :: WriteRedox | e) | eff) Unit) -> Interp dsl state (redox :: RedoxStore (read :: ReadRedox, write :: WriteRedox | e) | eff) -> Store state -> Free dsl (state -> state) -> Eff (redox :: RedoxStore (read :: ReadRedox, write :: WriteRedox | e) | eff) (Canceler (redox :: RedoxStore (read :: ReadRedox, write :: WriteRedox | e) | eff))
Dispatch dsl commands that will be interpreted in Aff monad. You have to write your own DSL for the state changes and an interpreter for it. Check out purescript-dsl-example or see the tests. This is useful if you want to have a batch dispatch that dispatches all the commands at once when the interpreter finished running your DSL.
#_dispatch Source
_dispatch :: forall e eff dsl state. (Error -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) Unit) -> (state -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) Unit) -> Interp dsl state (redox :: RedoxStore (read :: ReadRedox | e) | eff) -> Store state -> Free dsl (state -> state) -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) (Canceler (redox :: RedoxStore (read :: ReadRedox | e) | eff))
Re-exports from Redox.Store
#WriteRedox Source
data WriteRedox :: Effect
Effect for writing to the store
#WriteOnlyRedox Source
type WriteOnlyRedox = (write :: WriteRedox)
#SubscriptionId Source
#SubscribeRedox Source
data SubscribeRedox :: Effect
Effect for (un)subscribing to the store
#ReadWriteSubscribeRedox Source
type ReadWriteSubscribeRedox = (read :: ReadRedox, subscribe :: SubscribeRedox, write :: WriteRedox)
#ReadWriteRedox Source
type ReadWriteRedox = (read :: ReadRedox, write :: WriteRedox)
#ReadOnlyRedox Source
type ReadOnlyRedox = (read :: ReadRedox)
#CreateRedox Source
data CreateRedox :: Effect
Effect for creating Redox Store
#CreateReadWriteSubscribeRedox Source
type CreateReadWriteSubscribeRedox = (create :: CreateRedox, read :: ReadRedox, subscribe :: SubscribeRedox, write :: WriteRedox)
#unsubscribe Source
unsubscribe :: forall eff e state. Store state -> SubscriptionId -> Eff (redox :: RedoxStore (subscribe :: SubscribeRedox | e) | eff) Unit
Remove a subscription with a given id.
#subscribe Source
subscribe :: forall eff' eff e state. Store state -> (state -> Eff eff' Unit) -> Eff (redox :: RedoxStore (subscribe :: SubscribeRedox | e) | eff) SubscriptionId
Subscribe to store updates. Note that store updates are not run by the store itself. That is left to dispatch or the DSL interpreter. It returns id of the subscribed callback. You can use it to remove the subscription.
#setState Source
setState :: forall eff e state. Store state -> state -> Eff (redox :: RedoxStore (write :: WriteRedox | e) | eff) (Store state)
#performRedoxEff Source
performRedoxEff :: forall e a. Eff (redox :: RedoxStore e) a -> a
#modifyStore Source
modifyStore :: forall eff e state' state. (state -> state') -> Store state -> Eff (redox :: RedoxStore (read :: ReadRedox, write :: WriteRedox | e) | eff) (Store state')
#mkStore Source
mkStore :: forall eff e state. state -> Eff (redox :: RedoxStore (create :: CreateRedox | e) | eff) (Store state)
Make store with initial state. Store is a mutable container with a subscription mechanism.
#getSubscriptions Source
getSubscriptions :: forall eff e state. Store state -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) (Array (state -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) Unit))
Get subscriptions.
#getState Source
getState :: forall eff e state. Store state -> Eff (redox :: RedoxStore (read :: ReadRedox | e) | eff) state
Re-exports from Redox.Utils
#runSubscriptions Source
runSubscriptions :: forall f state. Functor f => Store state -> Cofree f state -> Cofree f state
Run subscriptions on each leaf of the Cofree
interpreter. You'll likely
want to use mkIncInterp
first so that the subscriptions run on the updated
state.
#mkIncInterp Source
mkIncInterp :: forall f state. Functor f => Store state -> Cofree f state -> Cofree f state
Make interpreter which updates the store on every step of computation.
You have to supply the store and interperter of type Cofree f state
.
Check out tests how you can use it. Note that it does not run
subscriptions. Use runSubscriptions
for that.
#hoistCofree' Source
hoistCofree' :: forall state f. Functor f => (f (Cofree f state) -> f (Cofree f state)) -> Cofree f state -> Cofree f state
A version of hoistCofree
, where nat
does not need to come from
a natural transformation. This corresponds to
applyMiddleware
in the redux library.
You can use this function to add effects to your interpreter, like
logging, optimistic updates, undo/redo stack, delayed actions...
#addLogger Source
addLogger :: forall f state. Functor f => (state -> String) -> Cofree f state -> Cofree f state
Add logger to the interpreter which logs updates on each leaf.
Note that leaves of the cofree interpreter might be visited more often
than when subsciptions run. If you are using dispatch
without
mkIncInterp
or runSubscriptions
the store will be updated only when
leaves of Free
DSL are reached, while this logger will log on
every leaf of your cofree interpreter.