listenSignal method

void listenSignal(
  1. ReadonlySignal target,
  2. void callback(), {
  3. String? debugLabel,
})

Watch signal value

Implementation

void listenSignal(
  ReadonlySignal<dynamic> target,
  void Function() callback, {
  String? debugLabel,
}) {
  final current = _signals[target.globalId];
  if (current?.listener?.cb.hashCode == callback.hashCode) return;
  current?.listener?.cleanup();
  final cb = createEffect(
    callback,
    debugLabel: debugLabel,
  );
  _signals[target.globalId] = (
    local: current?.local,
    target: target,
    listener: (cb: callback, cleanup: cb),
  );
}