Module

Redox

Package
purescript-redox
Repository
coot/purescript-redox

Re-exports from Redox.DSL

#dispatchP Source

dispatchP :: forall eff dsl state. (Error -> Eff (ReadWriteSubscribeRedox eff) Unit) -> (dsl -> state -> Aff eff state) -> Store state -> dsl -> Eff (ReadWriteSubscribeRedox eff) (Canceler (ReadWriteSubscribeRedox 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 to create such interpreter.

#dispatch Source

dispatch :: forall eff dsl state. (Error -> Eff (ReadWriteSubscribeRedox eff) Unit) -> (dsl -> state -> Aff (ReadWriteRedox eff) state) -> Store state -> dsl -> Eff (ReadWriteSubscribeRedox eff) (Canceler (ReadWriteSubscribeRedox 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.

#_dispatch Source

_dispatch :: forall eff dsl state. (Error -> Eff (ReadWriteSubscribeRedox eff) Unit) -> (state -> Eff (ReadWriteSubscribeRedox eff) Unit) -> (dsl -> state -> Aff (ReadWriteSubscribeRedox eff) state) -> Store state -> dsl -> Eff (ReadWriteSubscribeRedox eff) (Canceler (ReadWriteSubscribeRedox eff))

Re-exports from Redox.Store

#WriteRedox Source

data WriteRedox :: Effect

Effect for writing to the store

#WriteOnlyRedox Source

type WriteOnlyRedox eff = (writeRedox :: WriteRedox | eff)

#SubscribeRedox Source

data SubscribeRedox :: Effect

Effect for (un)subscribing to the store

#Store Source

data Store :: Type -> Type

Instances

#ReadWriteSubscribeRedox Source

type ReadWriteSubscribeRedox eff = (readRedox :: ReadRedox, subscribeRedox :: SubscribeRedox, writeRedox :: WriteRedox | eff)

#ReadWriteRedox Source

type ReadWriteRedox eff = (readRedox :: ReadRedox, writeRedox :: WriteRedox | eff)

#ReadRedox Source

data ReadRedox :: Effect

Effect for reading state of the store or retreaving store subscribers.

#ReadOnlyRedox Source

type ReadOnlyRedox eff = (readRedox :: ReadRedox | eff)

#CreateRedox Source

data CreateRedox :: Effect

Effect for creating Redox Store

#unsubscribe Source

unsubscribe :: forall eff state. Store state -> SubscriptionId -> Eff (subscribeRedox :: SubscribeRedox | eff) Unit

Remove a subscription with a given id.

#subscribe Source

subscribe :: forall eff state. Store state -> (state -> Eff (subscribeRedox :: SubscribeRedox | eff) Unit) -> Eff (subscribeRedox :: SubscribeRedox | 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 state. Store state -> state -> Eff (WriteOnlyRedox eff) (Store state)

#performWriteRedoxEff Source

performWriteRedoxEff :: forall a. Eff (WriteOnlyRedox ()) a -> a

#performReadWriteRedoxEff Source

#performReadRedoxEff Source

performReadRedoxEff :: forall a. Eff (ReadOnlyRedox ()) a -> a

#performCreateRedoxEff Source

performCreateRedoxEff :: forall a. Eff (createRedox :: CreateRedox) a -> a

#mkStoreG Source

mkStoreG :: forall state. state -> Store state

Make store outside of Eff monad (global).

#mkStore Source

mkStore :: forall eff state. state -> Eff (createRedox :: CreateRedox | eff) (Store state)

Make store with initial state. Store is a mutable container with a subscription mechanism.

#mapStore Source

mapStore :: forall eff state' state. (state -> state') -> Store state -> Eff (ReadWriteRedox eff) (Store state')

#getSubs Source

getSubs :: forall eff state. Store state -> Eff (readRedox :: ReadRedox | eff) (Array (state -> Eff (readRedox :: ReadRedox | eff) Unit))

Get subscriptions.

#getState Source

getState :: forall eff state. Store state -> Eff (ReadOnlyRedox eff) state

Re-exports from Redox.Utils

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

#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 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... For example a simple logger:

addLogger
  :: forall state f
   . (Functor f)
  => Cofree f state
  -> Cofree f state
addLogger interp = hoistCofree' nat interp
  where
    nat :: f (Cofree f state) -> f (Cofree f state)
    nat fa = g <$> fa

    g :: Cofree f state -> Cofree f state
    g cof = unsafePerformEff do
      -- Control.Comonad.Cofree.head 
      log $ unsafeCoerce (head cof)
      pure cof