9 #include <lager/state.hpp>
10 #include <lager/deps.hpp>
11 #include <lager/util.hpp>
12 #include <lager/context.hpp>
13 #include <lager/store.hpp>
18 template<
class Action,
22 class Deps = lager::deps<>,
23 class Tag = lager::automatic_tag>
33 StoreBase(Model initialModel, Reducer reducer, PH &&ph, Deps deps)
35 lager::make_state(
std::move(initialModel), Tag{}),
45 : m_d(
std::move(that.m_d))
49 m_d = std::move(that.m_d);
54 return m_d->dispatch(std::move(a));
57 operator lager::reader<Model>()
const {
61 lager::reader<Model>
reader()
const {
65 template<
class A2,
class D2>
77 Private(lager::state<Model, Tag> state,
81 : state(
std::move(state))
82 , reducer(
std::move(reducer))
86 , ctx([this](auto a) {
return dispatch(std::move(a)); }, this->ph, deps)
89 lager::state<Model, Tag> state;
95 return ph.createResolved(
true)
97 [
this, a=std::move(a)](
auto) {
98 if constexpr (hasEffect<Reducer, RetType, Model, Action, Deps>) {
99 auto [newModel, eff] = reducer(state.get(), a);
103 auto newModel = reducer(state.get(), a);
105 return ph.createResolved(
true);
110 std::shared_ptr<Private> m_d;
113 template<
class Action,
116 class Deps = lager::deps<>,
117 class Tag = lager::automatic_tag>
124 return zug::identity;
127 template<
class F1,
class ...Fs>
130 return zug::comp(std::forward<F1>(f1), std::forward<Fs>(fs)...);
134 template<
class Action,
135 class Tag = lager::automatic_tag,
141 auto makeStore(Model &&initialModel, Reducer &&reducer, PH &&ph, Enhancers &&...enhancers)
143 auto enhancer =
detail::compose(std::forward<Enhancers>(enhancers)...);
144 auto factory = enhancer(
145 [&](
auto actionTraits,
151 using ActionTraits = decltype(actionTraits);
153 using ModelF = decltype(model);
154 using ReducerF = decltype(reducer);
155 using PHF = decltype(ph);
156 using DepsF = decltype(deps);
158 using ActionT =
typename ActionTraits::type;
159 using ModelT = std::decay_t<ModelF>;
160 using ReducerT = std::decay_t<ReducerF>;
161 using DepsT = std::decay_t<DepsF>;
163 std::forward<ModelF>(initialModel), std::forward<ReducerF>(reducer),
164 std::forward<PHF>(ph), std::forward<DepsF>(deps));
167 lager::type_<Action>{},
168 std::forward<Model>(initialModel), std::forward<Reducer>(reducer),
169 std::forward<PH>(ph), lager::deps<>{}, Tag{});
Definition: promise-interface.hpp:122
StoreBase(const StoreBase &that)=delete
ContextBase< RetType, Action, Deps > ContextT
Definition: store.hpp:30
auto dispatch(Action a) -> PromiseT
Definition: store.hpp:53
StoreBase & operator=(const StoreBase &that)=delete
lager::reader< Model > reader() const
Definition: store.hpp:61
SingleTypePromiseInterface< RetType > PromiseInterfaceT
Definition: store.hpp:28
StoreBase(Model initialModel, Reducer reducer, PH &&ph, Deps deps)
Definition: store.hpp:33
StoreBase(StoreBase &&that)
Definition: store.hpp:44
StoreBase & operator=(StoreBase &&that)
Definition: store.hpp:48
EffectRetType RetType
Definition: store.hpp:27
ContextT context() const
Definition: store.hpp:70
SingleTypePromise< RetType > PromiseT
Definition: store.hpp:29
constexpr auto compose()
Definition: store.hpp:122
Definition: location.hpp:10
@ Private
Definition: client-model.hpp:41
auto makeStore(Model &&initialModel, Reducer &&reducer, PH &&ph, Enhancers &&...enhancers)
Definition: store.hpp:141
Definition: clientutil.hpp:217