ObservableComputation<T> class

A computed/derived value that automatically updates when its dependencies (observables) change.

ObservableComputation subscribes to one or more observables and recomputes its value whenever any dependency changes.

Usage:

final firstName = RiftObservable('Idris');
final lastName = RiftObservable('Ghamid');

final fullName = ObservableComputation(
  dependencies: [firstName, lastName],
  compute: () => '${firstName.value} ${lastName.value}',
);

fullName.listen((oldVal, newVal) => print('Full name: $newVal'));
firstName.set('Ahmed'); // Recomputes and notifies

Constructors

ObservableComputation({required List<RiftObservable> dependencies, required T compute()})
Creates an ObservableComputation that derives its value from dependencies using the compute function.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<T>
A stream of computed value changes.
no setter
value → T
The current computed value.
no setter

Methods

dispose() → void
Disposes the computation, removing dependency subscriptions.
forceRecompute() → void
Forces an immediate recomputation regardless of dependencies.
listen(void listener(T oldValue, T newValue)) → void
Registers a listener for computed value changes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(void listener(T oldValue, T newValue)) → void
Removes a previously registered listener.
toString() String
A string representation of this object.
inherited

Operators

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