setGroup method

void setGroup(
  1. TDependencyGroup<Object> group, {
  2. Entity groupEntity = const DefaultEntity(),
})

Updates the state by setting or replacing the group under the specified groupEntity.

Implementation

void setGroup(
  TDependencyGroup<Object> group, {
  Entity groupEntity = const DefaultEntity(),
}) {
  final currentGroup = _state[groupEntity];
  final equals = const MapEquality<Entity, Dependency>().equals(
    currentGroup,
    group,
  );
  if (!equals) {
    if (currentGroup != null) {
      for (final typeEntity in currentGroup.keys) {
        _detachFromTypeIndex(typeEntity, groupEntity);
      }
    }
    _state[groupEntity] = group;
    for (final typeEntity in group.keys) {
      (_typeIndex[typeEntity] ??= <Entity>{}).add(groupEntity);
    }
    _fireOnChange();
  }
}