replace<P> method

void replace<P>(
  1. P child, {
  2. String? tag,
})

Replaces an existing registered instance of type P with a new child instance.

If the existing instance is permanent, it will be forcefully deleted first before the new child is registered.

  • tag Optional tag to identify the instance.

Implementation

void replace<P>(P child, {String? tag}) {
  final info = getInstanceInfo<P>(tag: tag);
  final permanent = (info.isPermanent ?? false);
  delete<P>(tag: tag, force: permanent);
  put(child, tag: tag, permanent: permanent);
}