morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
store.hpp File Reference

morph::reactive::Store: user-intent view state, changed only by exhaustive messages. More...

#include <concepts>
#include <exception>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
#include <variant>
#include "../attributes.hpp"
#include "../core/bridge.hpp"
#include "../core/callback_scope.hpp"
#include "../core/registry.hpp"
#include "runtime.hpp"

Go to the source code of this file.

Classes

struct  morph::reactive::detail::UpdateCoversAll< Update, ViewState, Msg >
 Whether Update handles every alternative of the variant Msg. More...
struct  morph::reactive::detail::UpdateCoversAll< Update, ViewState, std::variant< Alts... > >
 Whether Update handles every alternative of std::variant<Alts...>. More...
struct  morph::reactive::detail::UpdateFrame
 One update in progress, on the stack of the send() running it. More...
class  morph::reactive::detail::UpdateGuard
 Marks a Store as inside its update for the guard's lifetime. More...
class  morph::reactive::Store< ViewState, Msg >
 User-intent view state — what is selected, typed, open — changed only by messages. More...

Concepts

concept  morph::reactive::ExhaustiveUpdate
 An update that handles every message: Update& is invocable as (ViewState&, Alt const&) for each alternative Alt of the std::variant Msg. Any Msg that is not a std::variant is never satisfied.

Functions

template<typename ViewState, typename Msg, typename Model, typename Sharing, typename Action, typename ToMsg, typename ToFailMsg>
void morph::reactive::request (Store< ViewState, Msg > &store, bridge::BridgeHandler< Model, Sharing > &handler, async::CallbackScope const &scope, Action action, ToMsg toMsg, ToFailMsg toFailMsg)
 Executes action and sends its result, or its failure, to store as one message.

Detailed Description

morph::reactive::Store: user-intent view state, changed only by exhaustive messages.

Specified in docs/spec/reactive/store.md.

Definition in file store.hpp.

Function Documentation

◆ request()

template<typename ViewState, typename Msg, typename Model, typename Sharing, typename Action, typename ToMsg, typename ToFailMsg>
void morph::reactive::request ( Store< ViewState, Msg > & store,
bridge::BridgeHandler< Model, Sharing > & handler,
async::CallbackScope const & scope,
Action action,
ToMsg toMsg,
ToFailMsg toFailMsg )

Executes action and sends its result, or its failure, to store as one message.

Callbacks land on the handler's GUI executor, which must be the Store's owner; each delivery is one batch. scope gates both. Query and Mutation follow the same delivery rules without a Store to send into.

Every call delivers: there is no latest-wins. Superseding an earlier call means stopping, resetting or destroying the scope it was given; Query provides latest-wins.

A throw from toMsg or from the update it sends to, on the success path, or from toFailMsg, is caught and logged by the Completion delivering it. It is not turned into a failure message.

Template Parameters
ViewStateThe Store's state type.
MsgThe Store's message variant.
ModelThe handler's model type.
SharingThe handler's sharing policy.
ActionThe action type.
ToMsgCallable (Result const&) -> alternative of Msg.
ToFailMsgCallable (std::exception_ptr const&) -> alternative of Msg.
Parameters
storeReceives the message. Must outlive every delivery scope does not gate.
handlerExecutes the action.
scopeGate: a reply arriving after it is stopped or destroyed is dropped.
actionThe action.
toMsgMaps the result to a message.
toFailMsgMaps the failure to a message.

Definition at line 202 of file store.hpp.