Module

React.Redox

Package
purescript-react-redox
Repository
coot/purescript-react-redox

#DispatchFn Source

type DispatchFn state dsl reff eff = Free dsl (state -> state) -> Eff (redox :: RedoxStore reff | eff) (Canceler (redox :: RedoxStore reff | eff))

#unsafeShallowEqual Source

unsafeShallowEqual :: forall a. Fn3 Boolean a a Boolean

Shallowly compare two objects. If the first argument is true it skips comparing the key property which should not be accessed on a property object.

#unsafeStrictEqual Source

unsafeStrictEqual :: forall a. Fn2 a a Boolean

Compare two objects using strict equality ===

#RedoxContext Source

newtype RedoxContext state dsl reff eff

#withStore Source

withStore :: forall eff reff dsl props state. Store state -> (Store state -> DispatchFn state dsl reff eff) -> ReactClass props -> Eff eff (ReactClass props)

You need to wrap your most top-level component with withStore. It makes the store and the bound dispatch function available through React context. Then you can connect a component with connect (or connect') and get access to the store and the dispatch function.

#ConnectState Source

newtype ConnectState state

Constructors

Instances

#connect' Source

connect' :: forall eff reff props' props dsl state' state. Proxy state -> Getter' state state' -> (DispatchFn state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff -> state' -> props' -> props) -> ReactClass props -> ReactSpec props' (ConnectState state') (context :: CONTEXT, redox :: RedoxStore (read :: ReadRedox, subscribe :: SubscribeRedox | reff) | eff)

You must wrap the resulting component with ReactHocs.accessContext from purescript-react-hocs. Checkout connect bellow. This function makes the redox store and dispatch function available through context. The first argument is a Lens that identifies the part of redox store's state that you want to subscribe for. The view on this lens will be checked for changes, so if you want to optimise your code, return as 'tight' lens as possible.

The second argument let you combine state and additional properties props' to get props of the class that you are connecting to the store. You can read the context with:

ReactHocs.readContext this >>= pure <<< _.redox :: Eff eff (RedoxContext state (Free dsl (state -> state))  eff)

#connect Source

connect :: forall eff' reff props' props dsl state' state. Proxy state -> Getter' state state' -> (DispatchFn state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> state' -> props' -> props) -> ReactClass props -> ReactClass props'

Like connect' but for ReactClass-es.

#withDispatch Source

withDispatch :: forall eff' reff dsl props' props state. (DispatchFn state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> props' -> props) -> ReactClass props -> ReactClass props'

If you just want to wrap your actions with a dispatch function use this function. Unlike connect' (and connect) it does not wrap your component inside another component.

#dispatch Source

dispatch :: forall eff reff state rState rProps dsl. ReactThis rProps rState -> Free dsl (state -> state) -> Eff (context :: CONTEXT, redox :: RedoxStore reff | eff) (Canceler (context :: CONTEXT, redox :: RedoxStore reff | eff))

If you wrapped your component with connect or connect' you can use this dispatch function to run your actions.

Modules
React.Redox