9 #include <lager/deps.hpp>
11 #include <boost/hana.hpp>
30 inline bool success()
const {
return m_succ; }
36 inline explicit operator bool()
const {
return success(); }
66 return data().
get().at(index).at(key);
78 inline std::string
dataStr(std::string key)
const {
79 return dataJson(key).template get<std::string>();
92 inline std::string
dataStr(
int index, std::string key)
const {
93 return dataJson(index, key).template get<std::string>();
108 auto data = a.
data().
get().is_array()
110 : json::array({a.
data().get()});
111 if (b.
data().
get().is_array()) {
112 for (
const auto &i: b.
data().
get()) {
116 data.push_back(b.
data().
get());
128 template<
class T,
class Action,
class Deps = lager::deps<>>
139 , m_dispatcher(
std::forward<Func>(dispatcher))
143 template<
class AnotherAction,
class AnotherDeps,
144 std::enable_if_t<std::is_convertible_v<Action, AnotherAction>
145 && std::is_convertible_v<AnotherDeps, Deps>,
int> = 0>
149 , m_dispatcher(that.m_dispatcher)
153 template<
class AnotherAction,
class AnotherDeps,
class Conv,
154 std::enable_if_t<std::is_convertible_v<std::invoke_result_t<Conv, Action>, AnotherAction>
155 && std::is_convertible_v<AnotherDeps, Deps>,
int> = 0>
160 thatDispatcher=that.m_dispatcher,
161 conv=
std::forward<Conv>(conv)](Action a) {
162 thatDispatcher(conv(std::move(a)));
168 return m_dispatcher(std::move(a));
172 return static_cast<Deps &
>(*this);
177 return m_ph.
create(std::move(func));
194 template<
class R2,
class A2,
typename D2>
197 std::function<
PromiseT(Action)> m_dispatcher;
200 template<
class A,
class D = lager::deps<>>
203 template<
class T,
class Action,
class Deps = lager::deps<>>
228 if constexpr (std::is_same_v<std::invoke_result_t<Func, ContextT>,
void>) {
229 m_d = [func=std::move(func)](
const auto &ctx) {
230 return ctx.createPromise(
232 func](
auto resolve) {
238 m_d = [func=std::move(func)](
const auto &ctx) {
256 template<
class A,
class D = lager::deps<>>
259 template<
class Reducer,
class RetType,
class Model,
class Action,
class Deps>
262 std::get<1>(std::declval<std::invoke_result_t<Reducer, Model, Action>>()))) {}
Definition: context.hpp:130
PromiseT createWaitingPromise(Func func) const
Definition: context.hpp:181
PromiseT dispatch(Action a) const
Definition: context.hpp:167
PromiseT createResolvedPromise(RetType v) const
Definition: context.hpp:185
PromiseInterfaceT promiseInterface() const
Definition: context.hpp:189
PromiseT createPromise(Func func) const
Definition: context.hpp:176
decltype(auto) deps()
Definition: context.hpp:171
SingleTypePromise< RetType > PromiseT
Definition: context.hpp:134
ContextBase(const ContextBase< RetType, AnotherAction, AnotherDeps > &that, Conv &&conv)
Definition: context.hpp:156
ContextBase(Func &&dispatcher, PromiseInterfaceT ph, Deps deps)
Definition: context.hpp:136
ContextBase(const ContextBase< RetType, AnotherAction, AnotherDeps > &that)
Definition: context.hpp:146
T RetType
Definition: context.hpp:132
Definition: context.hpp:205
EffectBase(Func func)
Constructor.
Definition: context.hpp:227
PromiseT operator()(const ContextT &ctx) const
Definition: context.hpp:248
T RetType
Definition: context.hpp:207
SingleTypePromise< RetType > PromiseT
Definition: context.hpp:208
ContextBase< RetType, Action, Deps > ContextT
Definition: context.hpp:209
Definition: context.hpp:19
EffectStatus()
Definition: context.hpp:21
bool success() const
Get whether this is successful.
Definition: context.hpp:30
EffectStatus(bool succ, JsonWrap d)
Definition: context.hpp:23
std::string dataStr(std::string key) const
Get the data string at key.
Definition: context.hpp:78
const JsonWrap & data() const
Get the attached data.
Definition: context.hpp:42
EffectStatus(bool succ)
Definition: context.hpp:22
const json & dataJson(int index, std::string key) const
Get the data at index at key.
Definition: context.hpp:65
const json & dataJson(std::string key) const
Get the data at key.
Definition: context.hpp:52
std::string dataStr(int index, std::string key) const
Get the data at index at key.
Definition: context.hpp:92
Definition: jsonwrap.hpp:23
const json & get() const
Definition: jsonwrap.hpp:38
PromiseT createResolveToPromise(std::function< void(ResolveToPromiseT)> f) const
Definition: promise-interface.hpp:280
PromiseT create(std::function< void(ResolveT)> f) const
Definition: promise-interface.hpp:276
PromiseT createResolved(DataT v) const
Definition: promise-interface.hpp:284
Definition: promise-interface.hpp:122
constexpr T defaultForPromiseThen(T)
Definition: promise-interface.hpp:113
Definition: location.hpp:10
EffectStatus dataCombineNone(EffectStatus)
Definition: context.hpp:121
EffectStatus createDefaultForPromiseThen(EffectStatus)
Definition: context.hpp:100
nlohmann::json json
Definition: jsonwrap.hpp:20
EffectStatus dataCombine(EffectStatus a, EffectStatus b)
Definition: context.hpp:105
constexpr bool hasEffect
Definition: context.hpp:260
Definition: clientutil.hpp:217