Redox.Utils
- Package
- purescript-redox
- Repository
- coot/purescript-redox
#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...
#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.
#mkIncInterpNat Source
mkIncInterpNat :: forall f state. Functor f => Store state -> Cofree f state -> Cofree f state
The map $ mkIncInterpNat store
is the natural transformation that runs
mkIncInterp
. If you have several natural transformations to run using
hoistCofree
you can compose them first and run them once.
#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, e.g.
runSubscriptions store <<< mkIncInterp store
or even better
hoistCofree' (map $ runSubscriptionsNat store <<< mkIncInterpNat store)
#runSubscriptionsNat Source
runSubscriptionsNat :: forall state f. Functor f => Store state -> Cofree f state -> Cofree f state
The map $ runSubscriptionsNat store
is the natural transformation of f
that runs runSubscriptions
.
#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.
#addLoggerNat Source
addLoggerNat :: forall state f. Functor f => (state -> String) -> Cofree f state -> Cofree f state