read method

E read({
  1. String? tag,
})

return the E associated to the provider, if the E is not saved into the ProvidersContainer the Element will be created

Implementation

E read({
  String? tag,
}) {
  final key = getKey(tag);
  final element = containerElements[key] as Element<E>?;
  if (element?.value != null) {
    return element!.value!;
  }

  final ref = element?.ref as Ref<A>? ?? Ref<A>(tag: tag);

  final createdElement = element ?? Element(ref: ref);

  createdElement.set(
    _creator.callback(ref),
  );

  containerElements[key] = createdElement;
  onElementValueAssigned(
    createdElement,
    _creator.autoDispose,
  );
  return createdElement.value!;
}