emit method

  1. @override
void emit(
  1. T val
)
override

Assigns a new value and notifies listeners if the value changed.

This method only notifies listeners if the new value is different from the current value (using != operator).

count.emit(5);        // Notifies if count.val != 5
count.emit(count.val + 1); // Increment and notify

The new value is also published to the stream.

Throws an assertion error in debug mode if called on a disposed signal.

Implementation

@override
void emit(T val) {
  if (_isUndoRedoing) {
    super.emit(val);
    return;
  }

  if (value == val) return;

  // Remove any redo history
  if (_index < _history.length - 1) {
    _history.removeRange(_index + 1, _history.length);
  }

  _history.add(val);
  if (_history.length > maxHistory) {
    _history.removeAt(0);
  } else {
    _index++;
  }

  super.emit(val);
}