subscribeWithPrevious<A> method

void Function() subscribeWithPrevious<A>(
  1. Atom<A> atom,
  2. void handler(
    1. A? previous,
    2. A value
    ), {
  3. bool fireImmediately = false,
})

Listen to changes of an atom's state, and retrieve the latest value.

Implementation

void Function() subscribeWithPrevious<A>(
  Atom<A> atom,
  void Function(A? previous, A value) handler, {
  bool fireImmediately = false,
}) {
  final node = _ensureNode(atom);

  A? previousValue = node._value;

  return subscribe(atom, (A nextValue) {
    handler(previousValue, nextValue);
    previousValue = nextValue;
  }, fireImmediately: fireImmediately);
}