ReactiveNode

class ReactiveNode

Base class for all reactive nodes in the system.

ReactiveNode is the abstract foundation of the reactive system. All reactive types (Signal, Computed, Effect) inherit from this class. It provides common functionality for dependency tracking, priority management, and metrics.

Since

v0.1.0

Users can inherit from ReactiveNode to create custom reactive types with specialized behavior, though this is an advanced use case.

Note

  • This class cannot be instantiated directly (has pure virtual methods).

  • Copy and move operations are deleted to prevent accidental duplication.

Subclassed by RxESP32::Effect< 1 >, RxESP32::Effect< sizeof…(Sources)>, RxESP32::Signal< T, 8, std::not_equal_to< T >, 0 >, RxESP32::Signal< bool, 1 >, RxESP32::Computed< T, MaxSources, MaxDeps, Filter >, RxESP32::Effect< MaxSources >, RxESP32::Signal< T, MaxDeps, Filter, HistorySize >

Public Types

enum class Type

Node type enumeration for runtime type identification.

Since

v0.1.0

Values:

enumerator Node

Base node type.

enumerator Signal

Signal node (state container)

enumerator Computed

Computed node (derived value)

enumerator Effect

Effect node (side effect)

Public Functions

ReactiveNode()

Default constructor.

Initializes the node with default priority and registers it for dependency graph tracking (if enabled).

Since

v0.1.0

virtual ~ReactiveNode()

Virtual destructor.

Cleans up resources and unregisters the node from the dependency graph.

Since

v0.1.0

ReactiveNode(const ReactiveNode&) = delete
ReactiveNode &operator=(const ReactiveNode&) = delete
ReactiveNode(ReactiveNode&&) = delete
ReactiveNode &operator=(ReactiveNode&&) = delete
inline virtual Type getType() const

Get the runtime type of this node.

Since

v0.1.0

Returns:

Type enum value indicating node type.

inline Priority getPriority() const

Get the dispatcher priority of this node.

Higher priority nodes are processed before lower priority nodes when multiple updates are pending in the dispatcher queue.

Since

v0.1.0

Computed<int> high_prio([]() { return criticalCalc(); });
high_prio.setPriority(Priority::High);

Priority p = high_prio.getPriority();
Serial.printf("Priority: %d\n", static_cast<int>(p));

Returns:

Priority level.

inline void setPriority(Priority priority)

Set the dispatcher priority of this node.

Changes the priority level for this node’s execution in the dispatcher. Higher priority nodes execute before lower priority nodes.

Since

v0.1.0

Effect<> critical([]() { handleCriticalUpdate(); });
critical.setPriority(Priority::Critical);

Note

Priority levels depend on RXESP32_PRIORITY_LEVELS configuration.

Parameters:
Priority priority

New priority level to assign.

inline const Metrics &getMetrics() const

Get the metrics for this node.

Computed<int> expensive([]() { return slowCalc(); });
// ... after some time ...
const auto& metrics = expensive.getMetrics();
Serial.printf("Executed %u times\n", metrics.execution_count);
Serial.printf("Average time: %.2f us\n", metrics.getAverageTimeUs());
Since

v0.1.0

Returns:

Const reference to Metrics struct.

inline void resetMetrics()

Reset all metrics to zero.

expensive.resetMetrics(); // Start fresh measurement
Since

v0.1.0

inline virtual const char *getName() const

Get the name of this node.

Since

v0.1.0

Returns:

C-string name, or default “Node” if not set.

inline virtual void getSourceNodes(ReactiveNode **out_sources, size_t &out_count, size_t max_count) const

Get the source nodes this node depends on.

Fills the provided array with pointers to all source nodes that this node depends on. Used for dependency graph visualization and analysis. Only applicable to Computed and Effect nodes.

Since

v0.1.0

ReactiveNode* sources[8];
size_t count = 0;
my_computed.getSourceNodes(sources, count, 8);

Serial.printf("Depends on %zu sources:\n", count);
for (size_t i = 0; i < count; i++) {
  Serial.printf(" - %s\n", sources[i]->getName());
}

Note

Requires RXESP32_ENABLE_DEPENDENCY_GRAPH to be enabled.

Parameters:
ReactiveNode **out_sources

Output array to fill with source node pointers.

size_t &out_count

Output parameter to store number of sources written.

size_t max_count

Maximum number of sources that can be written to the output array.

struct Metrics

Performance metrics for a reactive node.

Tracks execution statistics including count, timing, and notifications. Useful for profiling and optimizing reactive computations.

Since

v0.1.0

Note

Requires RXESP32_ENABLE_NODE_METRICS to be enabled.

Public Functions

inline Metrics()

Default constructor initializing all metrics to zero.

Since

v0.1.0

inline float getAverageTimeUs() const

Calculate average execution time.

Since

v0.1.0

Returns:

Average execution time in microseconds, or 0 if no executions.

Public Members

uint32_t execution_count

Total number of executions/recomputes.

uint64_t total_time_us

Total execution time in microseconds.

uint32_t last_execution_us

Last execution time in microseconds.

uint32_t min_execution_us

Minimum execution time.

uint32_t max_execution_us

Maximum execution time.

uint32_t notify_count

Number of times this node notified dependents.

See Also