morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::reactive::Effect Class Referencefinal

A side effect: runs once on construction, then in a flush after any source it read changed. More...

#include <signal.hpp>

Inheritance diagram for morph::reactive::Effect:
morph::reactive::detail::Node

Public Member Functions

template<typename F>
requires std::invocable<F&> && std::move_constructible<F>
 Effect (Runtime &runtime, F fn, std::size_t depth=0)
 Constructs the Effect and runs it once. Off the owner this is reported (detail::site::kOffOwner) and the Effect never runs.
 Effect (Effect const &)=delete
Effect & operator= (Effect const &)=delete
 Effect (Effect &&)=delete
Effect & operator= (Effect &&)=delete
Public Member Functions inherited from morph::reactive::detail::Node
 Node (std::shared_ptr< RuntimeCore > core, std::size_t depth=0)
 Constructs a node. Off the owner this is reported (site::kOffOwner) and the node is not counted towards the core's live nodes, whose counter belongs to the owner.
virtual ~Node ()
 Unlinks this node from its sources and observers, drops every reference the core holds to it, and tells a pull running on it that it is gone.
 Node (Node const &)=delete
Node & operator= (Node const &)=delete
 Node (Node &&)=delete
Node & operator= (Node &&)=delete
void markStale (Colour colour)
 Push phase: raises this node to colour and marks its observers Check.
bool updateIfNecessary ()
 Pull phase: brings this node up to date, recomputing only if a source really changed.
std::size_t countRun (std::uint64_t epoch) noexcept
 Counts one run of this Effect in the flush numbered epoch.
std::size_t depth () const noexcept
 How deeply the scope owning this node is nested; the flush runs shallower Effects first.
bool runsAfter (Node const &other) const noexcept
 Whether this node runs after other when both are queued: it is deeper, or as deep and newer.
std::uint64_t creationOrder () const noexcept
 Where this node stands in its runtime's creation order; among Effects of one depth, the flush runs older ones first.
void settle () noexcept
 Marks this node Clean without running it (a dropped queue entry).

Additional Inherited Members

Protected Member Functions inherited from morph::reactive::detail::Node
RuntimeCore & core () const noexcept
 The runtime core.
bool bornOnOwner () const noexcept
 Whether this node was constructed on the owner; one that was not is refused its work.
void trackRead () const
 Registers this node as a source of the innermost tracked run, if any.
void forceDirty () noexcept
 Marks this node Dirty, so the next pull recomputes it.
bool isPulling () const noexcept
 Whether a pull is bringing this node up to date right now. A read of the node from inside that pull can only come from its own run or from a source's run that reads it: a cycle.
void markObserversStale (Colour colour)
 Marks every observer of this node colour.
void adoptSources (std::vector< Node * > fresh)
 Replaces this node's sources with fresh, unlinking the ones no longer read.
void mergeSources (std::vector< Node * > fresh)
 Adds fresh to this node's sources without dropping any: what a failed run keeps.

Detailed Description

A side effect: runs once on construction, then in a flush after any source it read changed.

Queued Effects run shallowest scope first: an Effect a Scope makes carries that scope's depth, so an owner's Effects run before those of the scopes it owns. Among Effects of one depth, older ones run first.

An exception escaping it is a defect: reported (detail::site::kEffectThrew), and the flush stops. A run that throws keeps every source it has read, before and during that run, so a later change to any of them runs it again. A body may destroy its own Effect (a remount); the body's callable stays alive until the body returns, and the Effect is not touched afterwards.

Definition at line 350 of file signal.hpp.

Constructor & Destructor Documentation

◆ Effect()

template<typename F>
requires std::invocable<F&> && std::move_constructible<F>
morph::reactive::Effect::Effect ( Runtime & runtime,
F fn,
std::size_t depth = 0 )
inline

Constructs the Effect and runs it once. Off the owner this is reported (detail::site::kOffOwner) and the Effect never runs.

Template Parameters
FA callable taking no arguments; it may be move-only.
Parameters
runtimeThe runtime this effect belongs to.
fnThe body; every signal it reads becomes a dependency.
depthThe depth of the Scope that owns this Effect (Scope::depth()); zero for an Effect no scope owns.

Definition at line 361 of file signal.hpp.


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