doOnData method

ReactiveSubject<T> doOnData(
  1. void onData(
    1. T event
    )
)

Performs a side-effect action for each data event emitted by the source ReactiveSubject.

The onData callback receives the emitted item but does not modify it.

Usage:

final subject = ReactiveSubject<int>(initialValue: 1);
final sideEffect = subject.doOnData((value) => print('Value emitted: $value'));
sideEffect.stream.listen(print); // Prints: Value emitted: 1, then 1
subject.add(2); // Prints: Value emitted: 2, then 2

Implementation

ReactiveSubject<T> doOnData(void Function(T event) onData) {
  final newSubject = ReactiveSubject<T>();
  stream
      .doOnData(onData)
      .listen(newSubject.add, onError: newSubject.addError);
  return newSubject;
}