stream property

Stream<Snapshot<T>> get stream

Returns a stream of snapshots containing the computed value.

This stream emits a new Snapshot whenever the computed value changes due to changes in any of its source Reactive instances. The Snapshot contains both the previous value (Snapshot.oldValue) and the new value (Snapshot.newValue).

The stream is a BehaviorSubject, which means new subscribers immediately receive the current value.

Example:

final counter = Reactive(0);
final doubled = Computed([counter], (sources) => sources[0].value * 2);

// Subscribe to changes in the computed value
doubled.stream.listen((snapshot) {
  print('Doubled value changed from ${snapshot.oldValue} to ${snapshot.newValue}');
});

counter.value = 5; // Prints: "Doubled value changed from 0 to 10"

Implementation

Stream<Snapshot<T>> get stream => _controller.stream;