lager::
actions
¶Type used to declare contexes suporting multiple action types.
lager::
context
¶Provide some context for effectful functions, allowing them to control the event loop and dispatch new actions into the store.
A context is convertible to support “more restricted” actions. This is, if action B
is convertible to action A
, context<A>
is convertible to context<B>
, in this sense, contexes are contravariant to the action type. One can also specify multiple action types by using action<>
tag. This is useful to subset actions from a variant, here is an example:
struct action_A {};
struct action_B {};
struct action_C {};
using any_action = std::variant<action_A, action_B, action_C>>;
void some_effect(context<actions<action_A, action_B>> ctx)
{
if (...)
ctx.dispatch(action_A{});
else
ctx.dispatch(action_B{});
}
void other_effect(context<any_action> ctx)
{
some_effect(ctx);
...
}
void
or empty lager::actions<>
if context
shall have no dispatch()
method and only provide deps.Public Functions
context
()¶context
(const context<Actions_, Deps_> &ctx)¶context
(const context<Actions_, Deps_> &ctx, Converter c)¶context
(Dispatcher dispatcher, EventLoop &loop, deps_t deps)¶dispatch
(Action &&act) const¶loop
() const¶lager::
is_empty_effect
(const std::function<future(Ctx)> &v)¶Heuristically determine if the effect is empty or a noop operation.
lager::
is_empty_effect
(const Eff &v)¶lager::
invoke_reducer
(Reducer &&reducer, Model &&model, Action &&action, EffectHandler &&with_effect_handler, NoEffectHandler &&without_effect_handler)¶Invokes the reducer with the model and action and returns the resulting model. If the reducer returns an effect, it evaluates the handler passing the effect to it. This function can be used to generically handle both reducers with or without side-effects.
lager::
sequence
(effect<Actions1, Deps1> a, effect<Actions2, Deps2> b)¶Returns an effects that evalates the effects a and b in order.
lager::
sequence
(effect<A1, D1> a, effect<A2, D2> b, Effs&&... effects)¶lager::
effect
¶Effectful procedure that uses the store context.
lager::
result
¶Convenience type for specifying the result of reducers that return both a model and an effect.