MCPcopy Index your code
hub / github.com/angular/angular / delegateToFactory

Function delegateToFactory

packages/compiler/src/injectable_compiler_2.ts:154–183  ·  view source on GitHub ↗
(
  type: o.WrappedNodeExpr<any>,
  useType: o.WrappedNodeExpr<any>,
  unwrapForwardRefs: boolean,
)

Source from the content-addressed store, hash-verified

152}
153
154export function delegateToFactory(
155 type: o.WrappedNodeExpr<any>,
156 useType: o.WrappedNodeExpr<any>,
157 unwrapForwardRefs: boolean,
158): o.Expression {
159 if (type.node === useType.node) {
160 // The types are the same, so we can simply delegate directly to the type's factory.
161 // ```
162 // factory: type.ɵfac
163 // ```
164 return useType.prop('ɵfac');
165 }
166
167 if (!unwrapForwardRefs) {
168 // The type is not wrapped in a `forwardRef()`, so we create a simple factory function that
169 // accepts a sub-type as an argument.
170 // ```
171 // factory: function(t) { return useType.ɵfac(t); }
172 // ```
173 return createFactoryFunction(useType);
174 }
175
176 // The useType is actually wrapped in a `forwardRef()` so we need to resolve that before
177 // calling its factory.
178 // ```
179 // factory: function(t) { return core.resolveForwardRef(type).ɵfac(t); }
180 // ```
181 const unwrappedType = o.importExpr(Identifiers.resolveForwardRef).callFn([useType]);
182 return createFactoryFunction(unwrappedType);
183}
184
185function createFactoryFunction(type: o.Expression): o.ArrowFunctionExpr {
186 const t = new o.FnParam('__ngFactoryType__', o.DYNAMIC_TYPE);

Callers 2

compileServiceFunction · 0.90
compileInjectableFunction · 0.85

Calls 2

createFactoryFunctionFunction · 0.85
propMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…