MCPcopy Create free account
hub / github.com/angular/angular / recreateMatchingLViews

Function recreateMatchingLViews

packages/core/src/render3/hmr.ts:166–205  ·  view source on GitHub ↗

* Finds all LViews matching a specific component definition and recreates them. * @param importMeta `import.meta` information. * @param id HMR ID of the component. * @param oldDef Component definition to search for. * @param rootLView View from which to start the search.

(
  importMeta: ImportMetaExtended | null,
  id: string | null,
  newDef: ComponentDef<unknown>,
  oldDef: ComponentDef<unknown>,
  rootLView: LView,
)

Source from the content-addressed store, hash-verified

164 * @param rootLView View from which to start the search.
165 */
166function recreateMatchingLViews(
167 importMeta: ImportMetaExtended | null,
168 id: string | null,
169 newDef: ComponentDef<unknown>,
170 oldDef: ComponentDef<unknown>,
171 rootLView: LView,
172): void {
173 ngDevMode &&
174 assertDefined(
175 oldDef.tView,
176 'Expected a component definition that has been instantiated at least once',
177 );
178
179 const tView = rootLView[TVIEW];
180
181 // Use `tView` to match the LView since `instanceof` can
182 // produce false positives when using inheritance.
183 if (tView === oldDef.tView) {
184 ngDevMode && assertComponentDef(oldDef.type);
185 recreateLView(importMeta, id, newDef, oldDef, rootLView);
186 return;
187 }
188
189 for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
190 const current = rootLView[i];
191
192 if (isLContainer(current)) {
193 // The host can be an LView if a component is injecting `ViewContainerRef`.
194 if (isLView(current[HOST])) {
195 recreateMatchingLViews(importMeta, id, newDef, oldDef, current[HOST]);
196 }
197
198 for (let j = CONTAINER_HEADER_OFFSET; j < current.length; j++) {
199 recreateMatchingLViews(importMeta, id, newDef, oldDef, current[j]);
200 }
201 } else if (isLView(current)) {
202 recreateMatchingLViews(importMeta, id, newDef, oldDef, current);
203 }
204 }
205}
206
207/**
208 * Removes any cached renderers from the factory for the provided type.

Callers 1

ɵɵreplaceMetadataFunction · 0.85

Calls 5

assertDefinedFunction · 0.90
assertComponentDefFunction · 0.90
isLContainerFunction · 0.90
isLViewFunction · 0.90
recreateLViewFunction · 0.85

Tested by

no test coverage detected