Combine Redux action handlers into a type-safe reducer. See the test for a more detailed tutorial.

#Action Source

newtype Action (t :: Symbol) p


#ActionCreator Source

type ActionCreator t p = IsSymbol t => p -> Action t p

#createAction Source

createAction :: forall p t. IsSymbol t => p -> Action t p

The action creator. This function can create all of your actions with a type annotation. None of this action creator creator stuff.

createLoginAction :: User -> Action "LOG_IN_USER" User
createLoginAction = createAction

-- Or on-demand
action = createAction user :: Action "LOG_IN_USER"

#createReducer Source

createReducer :: forall p t s t16 t15 t11. RowCons t (Action t p) t16 t15 => IsSymbol t => ((Variant t11 -> s -> s) -> Variant t15 -> s -> s) -> s -> Action t p -> s

Takes an "action handler set" and creates a reducer. An action handler is a function of type s -> Action t p -> s where s is the state handled by the reducer. t is the type of action to handle and p is the type of the payload. An exmaple action handler may be of type logIn :: State -> Action "LOG_IN" User -> State.

#handle Source

handle :: forall a' a p t s. RowCons t (Action t p) a a' => IsSymbol t => (s -> Action t p -> s) -> (Variant a -> s -> s) -> Variant a' -> s -> s

Converts a single action handler into an "action handler set" handlers = handle logIn. This "action handler set" can be combined with other action handlers using combine or >>=>>.

#combine Source

combine :: forall a' a p t s t26. RowCons t (Action t p) a a' => IsSymbol t => (t26 -> Variant a -> s -> s) -> (s -> Action t p -> s) -> t26 -> Variant a' -> s -> s

Given an existing "action handler set", extend it to also handle an additional action. handers >>=>> logIn >>=>> logOut >>=>> createUser. You can combine as many action handlers as you want. >>=>> is the operator for combine. It has precedence 4 and may change in the future. Also, note that the first action handler must "seed" the "action handler set". This is done with handle.

#(>>=>>) Source

Operator alias for Aspen.combine (left-associative / precedence 4)