MCPcopy Index your code
hub / github.com/angular/angular / ɵɵreplaceMetadata

Function ɵɵreplaceMetadata

packages/core/src/render3/hmr.ts:81–118  ·  view source on GitHub ↗
(
  type: Type<unknown>,
  applyMetadata: (...args: [Type<unknown>, unknown[], ...unknown[]]) => void,
  namespaces: unknown[],
  locals: unknown[],
  importMeta: ImportMetaExtended | null = null,
  id: string | null = null,
)

Source from the content-addressed store, hash-verified

79 * @codeGenApi
80 */
81export function ɵɵreplaceMetadata(
82 type: Type<unknown>,
83 applyMetadata: (...args: [Type<unknown>, unknown[], ...unknown[]]) => void,
84 namespaces: unknown[],
85 locals: unknown[],
86 importMeta: ImportMetaExtended | null = null,
87 id: string | null = null,
88) {
89 ngDevMode && assertComponentDef(type);
90 const currentDef = getComponentDef(type)!;
91
92 // The reason `applyMetadata` is a callback that is invoked (almost) immediately is because
93 // the compiler usually produces more code than just the component definition, e.g. there
94 // can be functions for embedded views, the variables for the constant pool and `setClassMetadata`
95 // calls. The callback allows us to keep them isolate from the rest of the app and to invoke
96 // them at the right time.
97 applyMetadata.apply(null, [type, namespaces, ...locals]);
98
99 const {newDef, oldDef} = mergeWithExistingDefinition(currentDef, getComponentDef(type)!);
100
101 // TODO(crisbeto): the `applyMetadata` call above will replace the definition on the type.
102 // Ideally we should adjust the compiler output so the metadata is returned, however that'll
103 // require some internal changes. We re-add the metadata here manually.
104 (type as any)[NG_COMP_DEF] = newDef;
105
106 // If a `tView` hasn't been created yet, it means that this component hasn't been instantianted
107 // before. In this case there's nothing left for us to do aside from patching it in.
108 if (oldDef.tView) {
109 const trackedViews = getTrackedLViews().values();
110 for (const root of trackedViews) {
111 // Note: we have the additional check, because `IsRoot` can also indicate
112 // a component created through something like `createComponent`.
113 if (isRootView(root) && root[PARENT] === null) {
114 recreateMatchingLViews(importMeta, id, newDef, oldDef, root);
115 }
116 }
117 }
118}
119
120/**
121 * Merges two component definitions while preseving the original one in place.

Callers 1

replaceMetadataFunction · 0.90

Calls 8

assertComponentDefFunction · 0.90
getComponentDefFunction · 0.90
getTrackedLViewsFunction · 0.90
isRootViewFunction · 0.90
recreateMatchingLViewsFunction · 0.85
valuesMethod · 0.80
applyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…