|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
A source value. Reading it with get() inside a tracked run subscribes that run. More...
#include <signal.hpp>
Public Member Functions | |
| Signal (Runtime &runtime) | |
| Constructs a value-initialised signal. | |
| Signal (Runtime &runtime, T initial, EqualityPolicy policy=EqualityPolicy::Auto) | |
Constructs a signal holding initial. | |
| Signal (Signal const &)=delete | |
| Signal & | operator= (Signal const &)=delete |
| Signal (Signal &&)=delete | |
| Signal & | operator= (Signal &&)=delete |
| T const & | get () const |
| Reads the value, subscribing the innermost tracked run. | |
| T const & | peek () const noexcept |
| Reads the value without subscribing anything. | |
| void | set (T value) |
| Replaces the value and notifies observers, unless it equals the current one and the policy is EqualityPolicy::Auto. | |
| template<typename F> requires std::invocable<F, T&> | |
| void | mutate (F &&fn) |
| Changes the value in place and always notifies observers. | |
| 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. | |
A source value. Reading it with get() inside a tracked run subscribes that run.
set() skips a value equal to the current one when == is usable for T (kEqualityUsable) and the policy is EqualityPolicy::Auto; mutate() always notifies. Writes are refused, and reported, off the owner or inside a Computed. A read off the owner is reported and subscribes nothing.
| T | The value type; move-constructible and move-assignable. |
Definition at line 49 of file signal.hpp.
|
inlineexplicit |
Constructs a value-initialised signal.
| runtime | The runtime this signal belongs to. |
Definition at line 53 of file signal.hpp.
|
inline |
Constructs a signal holding initial.
| runtime | The runtime this signal belongs to. |
| initial | The initial value. |
| policy | Whether a write equal to the current value is skipped. |
Definition at line 61 of file signal.hpp.
|
inlinenodiscard |
Reads the value, subscribing the innermost tracked run.
Off the owner the read is reported (detail::site::kOffOwner) and proceeds untracked: it subscribes nothing and leaves the tracking state alone. The value it returns is then read without synchronisation against the owner's writes.
Definition at line 76 of file signal.hpp.
|
inlinenodiscardnoexcept |
Reads the value without subscribing anything.
Definition at line 85 of file signal.hpp.
|
inline |
Replaces the value and notifies observers, unless it equals the current one and the policy is EqualityPolicy::Auto.
| value | The new value. |
Definition at line 90 of file signal.hpp.
|
inline |
Changes the value in place and always notifies observers.
| F | A callable taking T&. |
| fn | The mutation. |
Definition at line 108 of file signal.hpp.