morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::PreferenceSync Class Reference

Talks to the server's preferences model (morph.preferences) for one application, through the interpreter's Dispatcher. More...

#include <preference_sync.hpp>

Public Member Functions

 PreferenceSync (Dispatcher &dispatcher, std::string application, std::function< void(std::string const &)> onError={})
 A sync for application.
void load (Screen &screen, async::CallbackScope const &scope, std::function< void(std::expected< PreferencesLoaded, std::string >)> done={})
 Loads screen's stored choices, in one call for all its points, and sets each that fits.
void changed (std::string const &screen, std::string const &point, Value const &value)
 Stores the user's choice at a point.
void reset (std::string const &screen, std::string const &point)
 Forgets the stored choice at a point, or at every point of a screen this sync has loaded.

Detailed Description

Talks to the server's preferences model (morph.preferences) for one application, through the interpreter's Dispatcher.

An application's InterpreterHost holds one, calls load after it mounts a screen, and forwards preferenceChanged to changed and resetPrefs to reset. No call names a person: the server keys every entry by the verified session's principal. All calls are made on the runtime's owner, where their replies arrive.

Definition at line 44 of file preference_sync.hpp.

Constructor & Destructor Documentation

◆ PreferenceSync()

morph::ui::PreferenceSync::PreferenceSync ( Dispatcher & dispatcher,
std::string application,
std::function< void(std::string const &)> onError = {} )
inline

A sync for application.

Parameters
dispatcherWhere model calls go. Borrowed: it must outlive the sync.
applicationThe application's id, the app of every key.
onErrorTold the reason when a write fails; empty to ignore failures.

Definition at line 50 of file preference_sync.hpp.

Member Function Documentation

◆ load()

void morph::ui::PreferenceSync::load ( Screen & screen,
async::CallbackScope const & scope,
std::function< void(std::expected< PreferencesLoaded, std::string >)> done = {} )
inline

Loads screen's stored choices, in one call for all its points, and sets each that fits.

A point with no stored entry keeps the document's default. A stored entry that does not parse as the point's type, or that the point refuses (Screen::setPreference), is ignored, so a new document version never breaks on an old choice. A screen with no points makes no call and reports at once.

Parameters
screenThe mounted screen. Borrowed until the reply is delivered or scope stops.
scopeGates the delivery: stop or destroy it with the screen, and nothing touches the screen after.
doneCalled once with what was applied and ignored, or the reason the call failed; may be empty.

Definition at line 62 of file preference_sync.hpp.

◆ changed()

void morph::ui::PreferenceSync::changed ( std::string const & screen,
std::string const & point,
Value const & value )
inline

Stores the user's choice at a point.

Parameters
screenThe screen's id.
pointThe point.
valueThe choice.

Definition at line 99 of file preference_sync.hpp.

◆ reset()

void morph::ui::PreferenceSync::reset ( std::string const & screen,
std::string const & point )
inline

Forgets the stored choice at a point, or at every point of a screen this sync has loaded.

Parameters
screenThe screen's id.
pointThe point, or all.

Definition at line 111 of file preference_sync.hpp.


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