hookInput method

  1. @nonVirtual
RoleHookInput<D> hookInput(
  1. RoleHookRequest request
)

Builds the input of this role's hooks and its providers' hooks from the pipeline's request.

The input holds the data of this role, typed as D, and only as much of the rest of the app as the role may see: the data and presence of its visibleRoles, and for a role that is openToAllModules the steps by hand of the app (see RoleHookInput.manualSetup). Data that does not apply, because its role or a role in its Contribution.when is absent, is left out. The conditions of data on what roles chose (Contribution.whenChosen) are the pipeline's to decide: once the roles have chosen, it leaves the data whose conditions do not hold out of request, and before, as in validation, it takes all of it.

This is the only place where data is cast to D, and data of another type fails here with an ArgumentError that names the contributor.

Implementation

@nonVirtual
RoleHookInput<D> hookInput(RoleHookRequest request) {
  final visible = visibleRoles;
  final applies = _appliesIn(request.presentRoles);
  return RoleHookInput<D>._(
    role: this,
    data: List.unmodifiable([
      for (final data in request.data)
        if (identical(data.role, this) && applies(data)) _typed(data),
    ]),
    present: {
      for (final role in request.presentRoles)
        if (visible.contains(role)) role,
    },
    visibleData: {
      for (final role in visible)
        role: List<RoleData<Object>>.unmodifiable(
          request.data.where(
            (data) => identical(data.role, role) && applies(data),
          ),
        ),
    },
    choice: request.choices[this],
    context: request.context,
    manualSetup: openToAllModules ? request.manualSetup : ManualSetup.none,
  );
}