React.Redox
- Package
- purescript-react-redox
- Repository
- coot/purescript-react-redox
#DispatchFn Source
type DispatchFn a state dsl reff eff = Free dsl (state -> state) -> Eff (redox :: RedoxStore reff | eff) a
#DispatchFnFiber Source
type DispatchFnFiber state dsl reff eff = DispatchFn (Fiber (redox :: RedoxStore reff | eff) Unit) state dsl reff eff
#unsafeShallowEq' Source
unsafeShallowEq' :: 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.
If you want to use strict value equality (===
in JavaScript), check out
Unsafe.Reference.unsafeRefEq
.
#unsafeShallowEq Source
unsafeShallowEq :: forall a. Boolean -> a -> a -> Boolean
#RedoxContext Source
newtype RedoxContext state dsl reff eff
#withStore Source
withStore :: forall eff reff dsl props state. Store state -> (Store state -> DispatchFnFiber 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. It serves the same purpose
as
Provider
class in react-redux
.
#StoreProvider Source
newtype StoreProvider state dsl reff eff
Constructors
StoreProvider { dispatch :: Store state -> DispatchFnFiber state dsl reff eff, store :: Store state }
#storeProvider Source
storeProvider :: forall eff reff dsl state. ReactClass (StoreProvider state dsl reff eff)
StoreProvider
component. This function provides store and the dispatch
function through the React context. This is an alternative to withStore
function.
#ConnectState Source
newtype ConnectState state
Constructors
ConnectState { sid :: Maybe SubscriptionId, state :: state }
Instances
Newtype (ConnectState state) _
#RedoxSpec Source
newtype RedoxSpec props state eff
Newtype wrapper around ReactSpec
. Use overRedoxSpec
to change the
underlying spec and asReactClass
to create a react class.
#overRedoxSpec Source
overRedoxSpec :: forall eff state props. (ReactSpec props state eff -> ReactSpec props state eff) -> RedoxSpec props state eff -> RedoxSpec props state eff
#asReactClass Source
asReactClass :: forall eff state props. RedoxSpec props state eff -> ReactClass props
#connect' Source
connect' :: forall eff reff props' props dsl state' state. Proxy state -> (state' -> state' -> Boolean) -> (props' -> props' -> Boolean) -> (state -> state') -> (DispatchFnFiber state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff -> state' -> props' -> props) -> ReactClass props -> RedoxSpec props' (ConnectState state') (context :: CONTEXT, redox :: RedoxStore (read :: ReadRedox, subscribe :: SubscribeRedox | reff) | eff)
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.
Use asReactClass
function to create react class from RedoxSpec
that
this function returns and overRedoxSpec
to possibly change the spec, for
example by changing the shouldComponentUpdate
react life cycle method.
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)
Note that the Eq
instance must be resolved when you apply this fuction.
Otherwise you will endup with
re-mounts.
This can lead to components loosing focus (in case of input
elements).
#connectEq' Source
connectEq' :: forall eff reff props' props dsl state' state. Eq state' => Eq props' => Proxy state -> (state -> state') -> (DispatchFnFiber state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff -> state' -> props' -> props) -> ReactClass props -> RedoxSpec props' (ConnectState state') (context :: CONTEXT, redox :: RedoxStore (read :: ReadRedox, subscribe :: SubscribeRedox | reff) | eff)
This is useful when you have (or can derive) a lawful Eq
instances for
state'
and props'
.
#connect Source
connect :: forall eff' reff props' props dsl state' state. Proxy state -> (state' -> state' -> Boolean) -> (props' -> props' -> Boolean) -> (state -> state') -> (DispatchFnFiber state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> state' -> props' -> props) -> ReactClass props -> ReactClass props'
Like connect'
but for ReactClass
-es.
#connectEq Source
connectEq :: forall eff' reff props' props dsl state' state. Eq state' => Eq props' => Proxy state -> (state -> state') -> (DispatchFnFiber state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> state' -> props' -> props) -> ReactClass props -> ReactClass props'
Like connect
but with Eq
constraints.
#connectV' Source
connectV' :: forall eff reff props' props dsl state' state. Proxy state -> (state' -> state' -> Boolean) -> (props' -> props' -> Boolean) -> (state -> state') -> (DispatchFn Unit state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff -> state' -> props' -> props) -> ReactClass props -> RedoxSpec props' (ConnectState state') (context :: CONTEXT, redox :: RedoxStore (read :: ReadRedox, subscribe :: SubscribeRedox | reff) | eff)
Like connect'
, only the dispatch function returns Eff eff Unit
rather
than Eff eff (Fiber eff Unit)
.
#connectEqV' Source
connectEqV' :: forall eff reff props' props dsl state' state. Eq state' => Eq props' => Proxy state -> (state -> state') -> (DispatchFn Unit state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff -> state' -> props' -> props) -> ReactClass props -> RedoxSpec props' (ConnectState state') (context :: CONTEXT, redox :: RedoxStore (read :: ReadRedox, subscribe :: SubscribeRedox | reff) | eff)
Like connectEq'
, only the dispatch function returns Eff eff Unit
rather
than Eff eff (Fiber eff Unit)
.
#connectEqV Source
connectEqV :: forall eff' reff props' props dsl state' state. Eq state' => Eq props' => Proxy state -> (state -> state') -> (DispatchFn Unit state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> state' -> props' -> props) -> ReactClass props -> ReactClass props'
Like connectEq
, only the dispatch function returns Eff eff Unit
rather
than Eff eff (Fiber eff Unit)
.
#connectV Source
connectV :: forall eff' reff props' props dsl state' state. Proxy state -> (state' -> state' -> Boolean) -> (props' -> props' -> Boolean) -> (state -> state') -> (DispatchFn Unit state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> state' -> props' -> props) -> ReactClass props -> ReactClass props'
Like connect
, only the dispatch function returns Eff eff Unit
rather
than Eff eff (Fiber eff Unit)
.
#withDispatch Source
withDispatch :: forall eff' reff dsl props' props state. (DispatchFnFiber 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.
#withDispatchV Source
withDispatchV :: forall eff' reff dsl props' props state. (DispatchFn Unit state dsl (read :: ReadRedox, subscribe :: SubscribeRedox | reff) eff' -> props' -> props) -> ReactClass props -> ReactClass props'
#dispatch Source
dispatch :: forall eff reff state rState rProps dsl. ReactThis rProps rState -> Free dsl (state -> state) -> Eff (context :: CONTEXT, redox :: RedoxStore reff | eff) (Fiber (context :: CONTEXT, redox :: RedoxStore reff | eff) Unit)
The component must be wrapped with accessContext
to use this function.
connect
and asReactClass
do that for you.
- Modules
- React.
Redox