registry method

VoidCallback registry(
  1. K key,
  2. V value
)

Implementation

VoidCallback registry(K key, V value) {
  assert(key != null, 'key must not be null.');
  assert(value != null, 'value must not be null.');

  _maps[key] ??= <V>{};
  _maps[key]?.add(value);
  return () {
    _maps[key]?.remove(value);
    if (_maps[key]?.isEmpty ?? true) {
      _maps.remove(key);
    }
  };
}