subscribeWithPrevious<T> method

void Function() subscribeWithPrevious<T>(
  1. Pod<T> pod,
  2. void handler(
    1. T? previous,
    2. T value
    ), {
  3. bool fireImmediately = false,
})

Listen to changes of a pod's state, and retrieve the latest value.

Implementation

void Function() subscribeWithPrevious<T>(
  Pod<T> pod,
  void Function(T? previous, T value) handler, {
  bool fireImmediately = false,
}) {
  final node = _ensureNode(pod);

  var previousValue = node._value as T?;

  return subscribe(
    pod,
    (T nextValue) {
      handler(previousValue, nextValue);
      previousValue = nextValue;
    },
    fireImmediately: fireImmediately,
  );
}