removeDependencyK method

Option<Dependency<Object>> removeDependencyK(
  1. Entity typeEntity, {
  2. Entity groupEntity = const DefaultEntity(),
})

Removes the dependency with the exact typeEntity under the specified groupEntity. If the group becomes empty after removal, the group itself is removed.

Implementation

Option<Dependency> removeDependencyK(
  Entity typeEntity, {
  Entity groupEntity = const DefaultEntity(),
}) {
  final group = _state[groupEntity];
  if (group == null) {
    return const None();
  }
  final syncKey = TypeEntity(Sync, [typeEntity]);
  final asyncKey = TypeEntity(Async, [typeEntity]);
  final (Option<Dependency> removed, Entity? removedKey) =
      switch (Option<Dependency>.from(group.remove(syncKey))) {
    final Some<Dependency> s => (s, syncKey),
    None() => switch (Option<Dependency>.from(group.remove(asyncKey))) {
        final Some<Dependency> s => (s, asyncKey),
        None() => (const None(), null),
      },
  };
  if (removedKey == null) return const None();
  _detachFromTypeIndex(removedKey, groupEntity);
  if (group.isEmpty) {
    _state.remove(groupEntity);
  }
  _fireOnChange();
  return removed.map((e) => e.transf());
}