register<TModel extends Pub> static method

TModel register<TModel extends Pub>(
  1. BuildContext context, {
  2. Iterable<Object>? aspects,
})

Register the consumer widget context to the Host with aspects, and add these aspects to regAspects. Return the TModel

Implementation

static TModel register<TModel extends Pub>(
  BuildContext context, {
  Iterable<Object>? aspects,
}) {
  assert(ifModelTypeCorrect(TModel, 'Host.register'));
  if (aspects == null || aspects.isEmpty) {
    final inheritedModel =
        InheritedMediator.inheritFrom<InheritedMediator<TModel>>(context);
    assert(ifInheritedModel<TModel>(inheritedModel));

    final model = inheritedModel!._model;
    // aspects is null, no need to `addRegAspects`
    return model;
  }

  final inheritedModel =
      InheritedMediator.inheritFrom<InheritedMediator<TModel>>(context,
          aspect: aspects);
  assert(ifInheritedModel<TModel>(inheritedModel));

  final model = inheritedModel!._model;

  /// Add [aspects] to the registered aspects of the model
  // if (aspects != null) {
  model.regAspects.addAll(aspects);
  // }
  return model;
}