onChangeDistinct<T> static method

LxWorker<T> onChangeDistinct<T>(
  1. LxReactive<T> source,
  2. void callback(
    1. T value
    ), {
  3. dynamic onProcessingError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Triggers callback when source emits a value distinct from the previous one.

Useful when values may be re-notified without changing (for example via manual refresh calls).

Implementation

static LxWorker<T> onChangeDistinct<T>(
  LxReactive<T> source,
  void Function(T value) callback, {
  Function(Object error, StackTrace stackTrace)? onProcessingError,
}) {
  var previous = source.value;
  return LxWorker<T>(
    source,
    (value) {
      if (value == previous) return;
      previous = value;
      callback(value);
    },
    onProcessingError: onProcessingError,
  );
}