unwatchSignal<T> function

void unwatchSignal<T>(
  1. BuildContext context,
  2. ReadonlySignal<T> signal
)

Remove all subscribers for a given signal for watchers

Implementation

void unwatchSignal<T>(BuildContext context, ReadonlySignal<T> signal) {
  // Remove keys for signal hashcode
  final items = [
    ..._watchSubscribers.entries.where((e) => e.key.$2 == signal.globalId),
  ];
  for (final item in items) {
    final (_, cleanup) = item.value;
    cleanup();
  }
  _watchSubscribers.removeWhere((key, value) => key.$2 == signal.globalId);
}