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
dependenciesusing thecomputefunction.
Properties
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