morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
signal.hpp File Reference

Signal<T>, Computed<T> and Effect: the nodes of a reactive graph. More...

#include <concepts>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <memory>
#include <optional>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include "detail/graph.hpp"
#include "runtime.hpp"

Go to the source code of this file.

Classes

class  morph::reactive::Signal< T >
 A source value. Reading it with get() inside a tracked run subscribes that run. More...
class  morph::reactive::Computed< T >
 A derived value: computed lazily on first read, cached, and recomputed only after a source it read really changed. More...
class  morph::reactive::Effect
 A side effect: runs once on construction, then in a flush after any source it read changed. More...

Enumerations

enum class  morph::reactive::EqualityPolicy : std::uint8_t { Auto , Always }
 Whether a Signal or Computed compares a new value with the current one before notifying. More...

Variables

template<typename T>
constexpr bool morph::reactive::kEqualityUsable = detail::EqualityUsable<std::remove_cv_t<T>>::value
 Whether == is usable for T, which is what the EqualityPolicy::Auto skip needs.

Detailed Description

Signal<T>, Computed<T> and Effect: the nodes of a reactive graph.

Specified in docs/spec/reactive/signals.md.

Definition in file signal.hpp.

Enumeration Type Documentation

◆ EqualityPolicy

enum class morph::reactive::EqualityPolicy : std::uint8_t
strong

Whether a Signal or Computed compares a new value with the current one before notifying.

Enumerator
Auto 

Skip a value equal to the current one, when == is usable for the type (kEqualityUsable).

Always 

Notify on every write or recomputation, even of an equal value.

Definition at line 26 of file signal.hpp.

Variable Documentation

◆ kEqualityUsable

template<typename T>
bool morph::reactive::kEqualityUsable = detail::EqualityUsable<std::remove_cv_t<T>>::value
inlineconstexpr

Whether == is usable for T, which is what the EqualityPolicy::Auto skip needs.

Checked through element types, not by std::equality_comparable alone: a standard container declares == for any element type, and comparing two of them fails to compile when the element has none. A type for which this is false always notifies.

Template Parameters
TThe value type.

Definition at line 40 of file signal.hpp.