Module

Redox

Package
purescript-redox
Repository
coot/purescript-redox

Re-exports from Redox.Free

#dispatchP Source

dispatchP :: forall dsl state. (Error -> Effect Unit) -> Interpret dsl state -> Store state -> Free dsl (state -> state) -> Effect (Fiber Unit)

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 dsl state. (Error -> Effect Unit) -> Interpret dsl state -> Store state -> Free dsl (state -> state) -> Effect (Fiber Unit)

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 dsl state. (Either Error state -> Effect Unit) -> Interpret dsl state -> Store state -> Free dsl (state -> state) -> Effect (Fiber Unit)

Re-exports from Redox.Store

#Store Source

data Store :: Type -> Type

#unsubscribe Source

unsubscribe :: forall state m. MonadEffect m => Store state -> SubscriptionId -> m Unit

Remove a subscription with a given id.

#subscribe Source

subscribe :: forall state m. MonadEffect m => Store state -> (state -> Effect Unit) -> m 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 state m. MonadEffect m => Store state -> state -> m (Store state)

#runStoreSubscriptions Source

runStoreSubscriptions :: forall state m. MonadEffect m => Store state -> m Unit

#modifyStore Source

modifyStore :: forall state' state m. MonadEffect m => (state -> state') -> Store state -> m (Store state')

#mkStoreG Source

mkStoreG :: forall state. state -> Store state

Make store outside of Eff monad (global).

#mkStore Source

mkStore :: forall state m. MonadEffect m => state -> m (Store state)

#getSubscriptions Source

getSubscriptions :: forall state m. MonadEffect m => Store state -> m (Array (state -> Effect Unit))

Get subscriptions.

#getState Source

getState :: forall state m. MonadEffect m => Store state -> m state

Re-exports from Redox.Utils

#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.

#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)

#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.

#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...

#composeM Source

composeM :: forall c b a g f. Functor f => Functor g => (a -> b -> c) -> Cofree f a -> Cofree g b -> Cofree (Product f g) c

Compose two interpreters.

#compose Source

compose :: forall b a g f. Functor f => Functor g => Cofree f a -> Cofree g b -> Cofree (Product f g) (Tuple a b)

Compose two interpreters. Check out an example This a specialization of composeM.

#addLoggerNat Source

addLoggerNat :: forall state f. Functor f => (state -> String) -> Cofree f state -> Cofree f state

#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.