remove method

Future<bool> remove(
  1. String signal, [
  2. Object? scope,
  3. WireListener? listener
])

Implementation

Future<bool> remove(String signal, [Object? scope, WireListener<dynamic>? listener]) async {
  final exists = hasSignal(signal);
  if (exists) {
    final withScope = scope != null;
    final withListener = listener != null;
    final toRemoveList = <Wire<dynamic>>[];
    await Future.forEach(_wireIdsBySignal[signal]!, (wireId) {
      if (_wireById.containsKey(wireId)) {
        final wire = _wireById[wireId]!;
        final isWrongScope = withScope && scope != wire.scope;
        final isWrongListener = withListener && !wire.listenerEqual(listener);
        if (isWrongScope || isWrongListener) return;
        toRemoveList.add(wire);
      }
    });
    await Future.forEach(toRemoveList, (Wire<dynamic> wireToRemove) => _removeWire(wireToRemove));
  }
  return exists;
}