Filters

Change detection predicates for fine-grained reactivity control.

Overview

Filters determine when a signal propagates changes to its dependents. ReactiveESP32 includes 50+ built-in filters organized by category.

namespace Filters

Collection of filter predicates for Signal change detection.

Filters define when a Signal’s value change should be considered “significant” and trigger notifications to dependents. Each filter is a callable that takes (old_value, new_value) and returns true if the change should propagate.

Since

v0.1.0

using namespace RxESP32::Filters;

// Only notify if absolute change > 5
Signal<int, 10, Numerical::OutsideTolerance<int, 5>> sensor(0);

// Only notify if value increases based on previous value
Signal<float, 10, Numerical::IncreasingValue<float>> temperature(0.0);

// Custom filter
template <typename T>
struct MyFilter {
  bool operator()(const T& old_value, const T& new_value) const {
    return // Custom logic;
  }
};

Filter Categories

Custom Filters

Create your own filters by implementing the filter interface:

// Filter example: only propagate if the new value is between 10 and 20
template <typename T>
struct MyCustomFilter {
   bool operator()(const T& old_value, const T& new_value) const {
      // Return true to allow propagation
      return (new_value >= 10 && new_value <= 20);
   }
};

// Signal of type int, max 8 dependents, using MyCustomFilter with int type
Signal<int, 8, MyCustomFilter<int>> signal(0);

// Now, signal will only notify dependents if the new value is between 10 and 20
signal.setValue(15); // Notifies dependents
signal.setValue(25); // Does not notify dependents

See Also