createProviderInstance method
ProviderSource
createProviderInstance(
- ProviderAst resolvedProvider,
- CompileDirectiveMetadata? directiveMetadata,
- List<
ProviderSource> providerSources, - int uniqueId,
override
Creates an eager instance for a provider and returns reference to source.
Implementation
@override
ProviderSource createProviderInstance(
ProviderAst resolvedProvider,
CompileDirectiveMetadata? directiveMetadata,
List<ProviderSource> providerSources,
int uniqueId,
) {
// Create a new field property for this provider.
final propName = '_${resolvedProvider.token.name}_${nodeIndex}_$uniqueId';
final providerValueExpressions = providerSources
.map((s) => s.build())
.whereType<o.Expression>()
.toList();
o.Expression? changeDetectorRefExpr;
if (resolvedProvider.providerType == ProviderAstType.Component) {
if (directiveMetadata?.changeDetection ==
ChangeDetectionStrategy.OnPush) {
changeDetectorRefExpr = componentView;
}
}
final providerExpr = view!.createProvider(
propName,
directiveMetadata,
resolvedProvider,
providerValueExpressions,
resolvedProvider.multiProvider,
resolvedProvider.eager,
this,
);
/// Accumulate directive instances on this element for later use.
if (resolvedProvider.providerType == ProviderAstType.Directive) {
_directiveInstances.add(providerExpr);
}
return ExpressionProviderSource(
resolvedProvider.token,
providerExpr,
changeDetectorRef: changeDetectorRefExpr,
);
}