saveSelf method

void saveSelf(
  1. BuildContext? context, {
  2. Object? owner,
})

Register this instance in the CoreContainer under its runtime type.

If already registered in the same container, owner is added to the internal owner set. If the container changes, the old registration is cleared first.

Called internally by ModelWidget and LogicWidget. Do not call manually.

Implementation

void saveSelf(BuildContext? context, {Object? owner}) {
  final container = context?.read<CoreContainer>() ?? top<CoreContainer>();
  final exposeOwner = owner ?? this;
  if (_exposed == true && identical(_container, container)) {
    _exposeOwners.add(exposeOwner);
    return;
  }

  _removeFromContainer();
  _exposeOwners
    ..clear()
    ..add(exposeOwner);
  final key = runtimeType;
  (container._exposedMap[key] ??= []).add(this);
  _container = container;
  _exposed = true;
}