morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::reactive::detail::Node Class Referenceabstract

A graph node: a source (Signal), an observer (Effect), or both (Computed). More...

#include <graph.hpp>

Inheritance diagram for morph::reactive::detail::Node:
morph::reactive::Computed< std::vector< morph::forms::CollectionRow > > morph::reactive::Computed< Encoding > morph::reactive::Computed< std::optional< morph::forms::FieldError > > morph::reactive::Computed< bool > morph::reactive::Computed< std::vector< morph::forms::ChoiceOption > > morph::reactive::Computed< std::optional< A > > morph::reactive::Computed< std::optional< Result > > morph::reactive::Computed< std::optional< std::string > > morph::reactive::Computed< std::string > morph::reactive::Computed< morph::ui::Value > morph::reactive::Computed< std::vector< morph::ui::HeadBadge > > morph::reactive::Computed< std::vector< morph::ui::HeadAction > > morph::reactive::Computed< std::vector< morph::ui::WorkspaceTabState > > morph::reactive::Computed< std::optional< morph::ui::WorkspaceTabId > > morph::reactive::Computed< Target > morph::reactive::Signal< std::optional< std::string > > morph::reactive::Signal< std::optional< morph::forms::PendingConfirm > > morph::reactive::Signal< bool > morph::reactive::Signal< std::exception_ptr > morph::reactive::Signal< std::size_t > morph::reactive::Signal< std::uint64_t > morph::reactive::Signal< std::string > morph::reactive::Signal< std::vector< std::shared_ptr< morph::forms::RowState > > > morph::reactive::Signal< std::optional< typename model::ActionTraits< A >::Result > > morph::reactive::Signal< std::optional< R > > morph::reactive::Signal< int > morph::reactive::Signal< std::set< std::string, std::less<> > > morph::reactive::Signal< std::shared_ptr< morph::ui::FormatContext const > > morph::reactive::Signal< ValueRecord > morph::reactive::Signal< std::optional< morph::ui::WorkspaceTabId > > morph::reactive::Signal< morph::ui::Value > morph::reactive::Signal< morph::ui::detail::RtScope * > morph::reactive::Signal< std::shared_ptr< morph::ui::detail::CacheEntry > > morph::reactive::Signal< RowT > morph::reactive::Computed< T > morph::reactive::Effect morph::reactive::Signal< T >

Public Member Functions

 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).

Protected Member Functions

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 graph node: a source (Signal), an observer (Effect), or both (Computed).

Non-copyable and non-movable: other nodes hold raw pointers to it, and its destructor unlinks it in both directions. A derived node supplies recompute() and isEffect() as private overrides; only Node calls them.

A node may be destroyed while it is being brought up to date (an Effect body that remounts the view owning it). The destructor tells the running pull and the running tracking frame, and neither touches the node again.

Definition at line 432 of file graph.hpp.

Constructor & Destructor Documentation

◆ Node()

morph::reactive::detail::Node::Node ( std::shared_ptr< RuntimeCore > core,
std::size_t depth = 0 )
inlineexplicit

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.

Parameters
coreThe runtime core this node belongs to.
depthHow deeply the scope owning this node is nested; queued Effects run shallowest first.

Definition at line 438 of file graph.hpp.

◆ ~Node()

virtual morph::reactive::detail::Node::~Node ( )
inlinevirtual

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.

Destroying a node off the owner is a misuse. It is reported (site::kOffOwner) but cannot be refused: the destructor still edits the owner's graph, queue and counters, and what that does beyond the report is undefined.

Definition at line 451 of file graph.hpp.

Member Function Documentation

◆ markStale()

void morph::reactive::detail::Node::markStale ( Colour colour)
inline

Push phase: raises this node to colour and marks its observers Check.

An Effect is queued when it leaves Clean. A node already at least as stale stops the walk, because its observers were marked when it turned stale, unless an observer has since ended Clean above it (exposeStaleSources()); then the walk passes through it once.

Parameters
colourDirty for a direct observer of a change, Check for a transitive one.

Definition at line 480 of file graph.hpp.

◆ updateIfNecessary()

bool morph::reactive::detail::Node::updateIfNecessary ( )
inline

Pull phase: brings this node up to date, recomputing only if a source really changed.

A pull that throws leaves the node Clean (so later changes still reach it) and rethrows. A pull during which the node is destroyed returns without touching it.

Returns
False when the node was destroyed during the pull: the caller must not touch it either.

Definition at line 520 of file graph.hpp.

◆ countRun()

std::size_t morph::reactive::detail::Node::countRun ( std::uint64_t epoch)
inlinenodiscardnoexcept

Counts one run of this Effect in the flush numbered epoch.

Parameters
epochThe current flush's number.
Returns
How many times it has run in that flush, this one included.

Definition at line 549 of file graph.hpp.

◆ depth()

std::size_t morph::reactive::detail::Node::depth ( ) const
inlinenodiscardnoexcept

How deeply the scope owning this node is nested; the flush runs shallower Effects first.

Returns
Zero for a node no scope owns.

Definition at line 559 of file graph.hpp.

◆ runsAfter()

bool morph::reactive::detail::Node::runsAfter ( Node const & other) const
inlinenodiscardnoexcept

Whether this node runs after other when both are queued: it is deeper, or as deep and newer.

Parameters
otherThe other node.
Returns
The flush queue's ordering.

Definition at line 564 of file graph.hpp.

◆ creationOrder()

std::uint64_t morph::reactive::detail::Node::creationOrder ( ) const
inlinenodiscardnoexcept

Where this node stands in its runtime's creation order; among Effects of one depth, the flush runs older ones first.

Returns
Greater than that of every node made from the same runtime before it; zero for a node constructed off the owner, which is never queued.

Definition at line 572 of file graph.hpp.

◆ settle()

void morph::reactive::detail::Node::settle ( )
inlinenoexcept

Marks this node Clean without running it (a dropped queue entry).

Definition at line 575 of file graph.hpp.

◆ core()

RuntimeCore & morph::reactive::detail::Node::core ( ) const
inlinenodiscardprotectednoexcept

The runtime core.

Returns
The core this node belongs to.

Definition at line 583 of file graph.hpp.

◆ bornOnOwner()

bool morph::reactive::detail::Node::bornOnOwner ( ) const
inlinenodiscardprotectednoexcept

Whether this node was constructed on the owner; one that was not is refused its work.

Returns
The owner check the constructor made.

Definition at line 587 of file graph.hpp.

◆ trackRead()

void morph::reactive::detail::Node::trackRead ( ) const
inlineprotected

Registers this node as a source of the innermost tracked run, if any.

Definition at line 590 of file graph.hpp.

◆ forceDirty()

void morph::reactive::detail::Node::forceDirty ( )
inlineprotectednoexcept

Marks this node Dirty, so the next pull recomputes it.

Definition at line 598 of file graph.hpp.

◆ isPulling()

bool morph::reactive::detail::Node::isPulling ( ) const
inlinenodiscardprotectednoexcept

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.

Returns
True between the start and the end of updateIfNecessary() on this node.

Definition at line 603 of file graph.hpp.

◆ markObserversStale()

void morph::reactive::detail::Node::markObserversStale ( Colour colour)
inlineprotected

Marks every observer of this node colour.

Parameters
colourThe colour to raise them to.

Definition at line 607 of file graph.hpp.

◆ adoptSources()

void morph::reactive::detail::Node::adoptSources ( std::vector< Node * > fresh)
inlineprotected

Replaces this node's sources with fresh, unlinking the ones no longer read.

Strong guarantee: linking the new sources is the only step that allocates, and it runs first; if it throws, the links it made are undone, so no source keeps a link this node does not list.

Parameters
freshThe sources the latest run read.

Definition at line 618 of file graph.hpp.

◆ mergeSources()

void morph::reactive::detail::Node::mergeSources ( std::vector< Node * > fresh)
inlineprotected

Adds fresh to this node's sources without dropping any: what a failed run keeps.

Parameters
freshThe sources the failed run read before it threw.

Definition at line 645 of file graph.hpp.


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