Module

Radox

Package
purescript-radox
Repository
danieljharvey/purescript-radox

Re-exports from Radox.Internal.CreateStore

#lift Source

lift :: forall r dunno action label. Cons label action dunno r => HasLabel action label => IsSymbol label => action -> Variant r

When we dispatch an action, we need to first lift it into our main Variant type Thus, to dispatch an Up action we'd do dispatch (lift Up)

#emptyStore Source

emptyStore :: forall actionType stateType. stateType -> RadoxStore actionType stateType

Things like React Context require us to provide a starting value, this allows us to pass one without using Effect.

#createStore Source

createStore :: forall actionType stateType. stateType -> Listeners stateType -> CombinedReducer actionType stateType -> Effect (RadoxStore actionType stateType)

This creates a new Radox store

initialState is how our state looks when we start

listeners are an array of stateType -> Effect Unit functions that will be sent the new state everything it is updated

'rootReduceris the function that takes ouractionTypeand astateTypeand returns the newstateType`

This returns a RadoxStore, which has a dispatch function for sending new actions and a getState function

Re-exports from Radox.Internal.Store

#update Source

update :: forall actionType stateType. Ref stateType -> Listeners stateType -> Effect stateType -> CombinedReducer actionType stateType -> actionType -> Effect Unit

This takes our action runs it through the reducers, updates listeners with the result And then updates the ref with the new value Note actionType must have have been lift-ed into the Variant for use here

#getState Source

getState :: forall stateType. Ref stateType -> Effect stateType

Read the current state this is saved in the mutable Ref and returns it

Re-exports from Radox.Internal.Types

#ReducerReturn Source

data ReducerReturn stateType

Type of return value from reducer

Constructors

#Reducer Source

type Reducer actionType stateType = actionType -> stateType -> stateType

Type for a reducer that does need to trigger any side effects

#RadoxStore Source

type RadoxStore combinedActionType stateType = { dispatch :: Dispatcher combinedActionType, getState :: Effect stateType, state :: stateType }

Type of store shared around so that the state can be accessed without needing Effect

#RadoxEffects Source

type RadoxEffects combinedActionType stateType = { dispatch :: combinedActionType -> Effect Unit, getState :: Effect stateType, state :: stateType }

#Listeners Source

type Listeners stateType = Array (stateType -> Effect Unit)

A Listener is a function that takes the new state and returns Effect Unit (so that it can use it to do something interesting, hopefully)

#EffectfulReducer Source

type EffectfulReducer actionType stateType combinedActionType = RadoxEffects combinedActionType stateType -> actionType -> stateType -> ReducerReturn stateType

Type for any user-created Reducer function that takes an Action for a specific reducer, the entire state, and returns a new copy of the state

#Dispatcher Source

type Dispatcher combinedActionType = combinedActionType -> Effect Unit

A Dispatcher is the function that allows different parts of our app to send actions to the reducers and make Things Happen.

#CombinedReducer Source

type CombinedReducer combinedActionType stateType = RadoxEffects combinedActionType stateType -> stateType -> combinedActionType -> ReducerReturn stateType

Type for the user-created Combined Reducer function, that takes a Variant of any action, and pipes it to the correct Reducer function, then returns the new state

#HasLabel Source

class HasLabel a (p :: Symbol) | a -> p

Typeclass that links any given Action sum type to the label it holds in the Combined Reducer / variant