getViewFactory function
Returns a callable expression for the component
view factory named name
.
If component
is generic, the view factory will flow the type parameters of
the parent view as type arguments to the embedded view.
Note: It's assumed that name
originates from an invocation of
getViewFactoryName with the same component
.
Implementation
o.Expression getViewFactory(
CompileDirectiveMetadata component,
String name,
) {
final viewFactoryVar = o.variable(name);
if (component.originType!.typeParameters.isEmpty) {
return viewFactoryVar;
}
final parameters = [o.FnParam('parentView'), o.FnParam('parentIndex')];
final arguments = parameters.map((p) => o.variable(p.name)).toList();
return o.FunctionExpr(parameters, [
o.ReturnStatement(o.InvokeFunctionExpr(
viewFactoryVar,
arguments,
component.originType!.typeParameters.map((t) => t.toType()).toList(),
)),
]);
}