morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::Form< A, M, S > Class Template Reference

A form over action A: a FormSession built from schemaJson<A>(), submitting through a BridgeHandler, with typed set<>, value() and lastResult(). More...

#include <typed_form.hpp>

Public Types

using Result = model::ActionTraits<A>::Result
 The action's registered result type.
template<auto Member>
using MemberValue = bridge::detail::MemberPointerTraits<decltype(Member)>::ValueType
 The type of the member Member points to.

Public Member Functions

 Form (reactive::Runtime &runtime, bridge::BridgeHandler< M, S > &handler, ChoiceFetcher choices, FormSessionOptions options={})
 Form (Form const &)=delete
Form & operator= (Form const &)=delete
 Form (Form &&)=delete
Form & operator= (Form &&)=delete
FormSession & session () noexcept
 The session: fields, readiness, body, submission.
template<auto Member>
void set (MemberValue< Member > value)
 Sets one member, encoded with its field's encoder; a programmatic change, so nothing is submitted.
std::optional< A > value () const
 The body decoded into A. Tracked.
bool ready () const
 Whether the form can submit: the session is ready, which includes A's own validate(). Tracked.
std::optional< Result > const & lastResult () const
 The last successful result: the session's last reply, decoded. Tracked.
bool pending () const
 Whether a submission is in flight. Tracked.
std::exception_ptr error () const
 The last failure. Tracked.

Detailed Description

template<class A, class M, class S = bridge::NoSharing>
class morph::forms::Form< A, M, S >

A form over action A: a FormSession built from schemaJson<A>(), submitting through a BridgeHandler, with typed set<>, value() and lastResult().

Non-copyable and non-movable: its session and in-flight callbacks point into it.

Template Parameters
AThe action type (registered with BRIDGE_REGISTER_ACTION).
MThe model type the handler talks to.
SThe handler's sharing policy.

Definition at line 52 of file typed_form.hpp.

Member Typedef Documentation

◆ Result

template<class A, class M, class S = bridge::NoSharing>
using morph::forms::Form< A, M, S >::Result = model::ActionTraits<A>::Result

The action's registered result type.

Definition at line 55 of file typed_form.hpp.

◆ MemberValue

template<class A, class M, class S = bridge::NoSharing>
template<auto Member>
using morph::forms::Form< A, M, S >::MemberValue = bridge::detail::MemberPointerTraits<decltype(Member)>::ValueType

The type of the member Member points to.

Template Parameters
MemberA pointer to a data member of A.

Definition at line 60 of file typed_form.hpp.

Constructor & Destructor Documentation

◆ Form()

template<class A, class M, class S = bridge::NoSharing>
morph::forms::Form< A, M, S >::Form ( reactive::Runtime & runtime,
bridge::BridgeHandler< M, S > & handler,
ChoiceFetcher choices,
FormSessionOptions options = {} )
inline
Parameters
runtimeThe runtime; its owner must be handler's callback executor. Borrowed.
handlerExecutes the action. Borrowed: it must outlive the form.
choicesFetches Choice options; may be empty when A has no Choice member.
optionsLocale, translations, display zone; an accepts gate is kept and joined with ActionValidator<A>.
Exceptions
std::logic_errorfrom FormModel::forAction<A>() when schemaJson<A>() does not read as a form model.

Definition at line 69 of file typed_form.hpp.

Member Function Documentation

◆ session()

template<class A, class M, class S = bridge::NoSharing>
FormSession & morph::forms::Form< A, M, S >::session ( )
inlinenodiscardnoexcept

The session: fields, readiness, body, submission.

Returns
The session.

Definition at line 101 of file typed_form.hpp.

◆ set()

template<class A, class M, class S = bridge::NoSharing>
template<auto Member>
void morph::forms::Form< A, M, S >::set ( MemberValue< Member > value)
inline

Sets one member, encoded with its field's encoder; a programmatic change, so nothing is submitted.

Template Parameters
MemberA pointer to a data member of A, e.g. &Deposit::amount.
Parameters
valueThe member's value.

Definition at line 108 of file typed_form.hpp.

◆ value()

template<class A, class M, class S = bridge::NoSharing>
std::optional< A > morph::forms::Form< A, M, S >::value ( ) const
inlinenodiscard

The body decoded into A. Tracked.

Returns
The action while the form is ready, else std::nullopt.

Definition at line 116 of file typed_form.hpp.

◆ ready()

template<class A, class M, class S = bridge::NoSharing>
bool morph::forms::Form< A, M, S >::ready ( ) const
inlinenodiscard

Whether the form can submit: the session is ready, which includes A's own validate(). Tracked.

Returns
true when ready.

Definition at line 121 of file typed_form.hpp.

◆ lastResult()

template<class A, class M, class S = bridge::NoSharing>
std::optional< Result > const & morph::forms::Form< A, M, S >::lastResult ( ) const
inlinenodiscard

The last successful result: the session's last reply, decoded. Tracked.

Returns
The typed result, or std::nullopt before the first success.

Definition at line 125 of file typed_form.hpp.

◆ pending()

template<class A, class M, class S = bridge::NoSharing>
bool morph::forms::Form< A, M, S >::pending ( ) const
inlinenodiscard

Whether a submission is in flight. Tracked.

Returns
true while one is.

Definition at line 129 of file typed_form.hpp.

◆ error()

template<class A, class M, class S = bridge::NoSharing>
std::exception_ptr morph::forms::Form< A, M, S >::error ( ) const
inlinenodiscard

The last failure. Tracked.

Returns
The exception, or null.

Definition at line 133 of file typed_form.hpp.


The documentation for this class was generated from the following file: