cacheEntities<O> method

  1. @override
void cacheEntities<O>(
  1. List<O> entities, [
  2. dynamic idGetter(
    1. O o
    )?
])
override

Caches the List entities. This is called by the entity decoder/loader. See cacheEntity.

Implementation

@override
void cacheEntities<O>(List<O> entities, [dynamic Function(O o)? idGetter]) {
  Type? entityTYpe;
  Map<dynamic, Object>? typeEntities;
  Map<Object, Object Function()>? typeEntitiesInstantiators;

  for (var e in entities) {
    var id = getEntityID<O>(e, idGetter: idGetter);
    if (id == null) continue;

    if (entityTYpe != e.runtimeType) {
      entityTYpe = e.runtimeType;

      var entities = _entities ??= {};

      typeEntities = entities[entityTYpe] ??= <Object, Object>{};
      typeEntitiesInstantiators = _entitiesInstantiators?[entityTYpe];
    }

    typeEntities![id] = e!;
    typeEntitiesInstantiators?.remove(id);
  }
}