FluxivityMiddleware<T> class abstract

An abstract class defining the interface for middleware plugins in Fluxivity.

Middleware plugins allow you to intercept and modify the behavior of reactive state changes. They can be used for various purposes such as logging, validation, persistence, or any custom behavior you want to add to your reactive state.

Middleware implementations can be attached to both Reactive and Computed instances and will be executed in the order they are provided.

Example of a simple logging middleware:

class LoggingMiddleware<T> extends FluxivityMiddleware<T> {
  @override
  void beforeUpdate(T oldValue, T newValue) {
    print('About to update from $oldValue to $newValue');
  }

  @override
  void afterUpdate(T oldValue, T newValue) {
    print('Updated from $oldValue to $newValue');
  }

  @override
  void onError(Object error, StackTrace stackTrace) {
    print('Error occurred: $error');
  }

  @override
  bool shouldEmit(T oldValue, T newValue) {
    return true; // Always emit the update
  }
}

// Usage
final counter = Reactive(0, middlewares: [LoggingMiddleware<int>()]);
Implementers

Constructors

FluxivityMiddleware()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

afterUpdate(T oldValue, T newValue) → void
Called immediately after a value has been updated.
beforeUpdate(T oldValue, T newValue) → void
Called immediately before a value is updated.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(Object error, StackTrace stackTrace) → void
Called when an error occurs during computation in a Computed instance.
shouldEmit(T oldValue, T newValue) bool
Determines whether a value change should trigger a notification to listeners.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited