MCPcopy
hub / github.com/angular/angular / setClassMetadataAsync

Function setClassMetadataAsync

packages/core/src/render3/metadata.ts:60–76  ·  view source on GitHub ↗
(
  type: Type<any> | AbstractType<any>,
  dependencyLoaderFn: () => Array<Promise<Type<unknown> | AbstractType<unknown>>>,
  metadataSetterFn: (...types: (Type<unknown> | AbstractType<unknown>)[]) => void,
)

Source from the content-addressed store, hash-verified

58 * @param metadataSetterFn Function that forms a scope in which the `setClassMetadata` is invoked
59 */
60export function setClassMetadataAsync(
61 type: Type<any> | AbstractType<any>,
62 dependencyLoaderFn: () => Array<Promise<Type<unknown> | AbstractType<unknown>>>,
63 metadataSetterFn: (...types: (Type<unknown> | AbstractType<unknown>)[]) => void,
64): () => Promise<Array<Type<unknown> | AbstractType<unknown>>> {
65 const componentClass = type as any; // cast to `any`, so that we can monkey-patch it
66 componentClass[ASYNC_COMPONENT_METADATA_FN] = () =>
67 Promise.all(dependencyLoaderFn()).then((dependencies) => {
68 metadataSetterFn(...dependencies);
69 // Metadata is now set, reset field value to indicate that this component
70 // can by used/compiled synchronously.
71 componentClass[ASYNC_COMPONENT_METADATA_FN] = ASYNC_METADATA_LOADED;
72
73 return dependencies;
74 });
75 return componentClass[ASYNC_COMPONENT_METADATA_FN];
76}
77
78/**
79 * Adds decorator, constructor, and property metadata to a given type via static metadata fields

Callers 3

getAOTCompiledComponentFunction · 0.90
test_bed_spec.tsFile · 0.90

Calls 2

thenMethod · 0.65
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…