setEntity method

Entity setEntity(
  1. Entity entity
)

This function actually sets the entity in the list. Left public so that if you want to use your own method for creating entities you can, as long as you call this method so the system tracks the entity.

Implementation

Entity setEntity(Entity entity) {
  final current = _entities.value;
  // If we have a custom key generator use that.
  late final T key;
  if (uniqueKeyGeneratorFunction != null) {
    key = uniqueKeyGeneratorFunction!(entity);
  } else {
    key = entity.guid as T;
  }
  final newList = Map.fromIterables([...current.keys, key], [...current.values, entity]);
  _entities.add(newList);
  // Return the entity.
  return _entities.value[entity.guid]!;
}