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

Function getOrCreateNodeInjectorForNode

packages/core/src/render3/di.ts:194–229  ·  view source on GitHub ↗
(
  tNode: TElementNode | TContainerNode | TElementContainerNode,
  lView: LView,
)

Source from the content-addressed store, hash-verified

192 * @returns Node injector
193 */
194export function getOrCreateNodeInjectorForNode(
195 tNode: TElementNode | TContainerNode | TElementContainerNode,
196 lView: LView,
197): number {
198 const existingInjectorIndex = getInjectorIndex(tNode, lView);
199 if (existingInjectorIndex !== -1) {
200 return existingInjectorIndex;
201 }
202
203 const tView = lView[TVIEW];
204 if (tView.firstCreatePass) {
205 tNode.injectorIndex = lView.length;
206 insertBloom(tView.data, tNode); // foundation for node bloom
207 insertBloom(lView, null); // foundation for cumulative bloom
208 insertBloom(tView.blueprint, null);
209 }
210
211 const parentLoc = getParentInjectorLocation(tNode, lView);
212 const injectorIndex = tNode.injectorIndex;
213
214 // If a parent injector can't be found, its location is set to -1.
215 // In that case, we don't need to set up a cumulative bloom
216 if (hasParentInjector(parentLoc)) {
217 const parentIndex = getParentInjectorIndex(parentLoc);
218 const parentLView = getParentInjectorView(parentLoc, lView);
219 const parentData = parentLView[TVIEW].data as any;
220 // Creates a cumulative bloom filter that merges the parent's bloom filter
221 // and its own cumulative bloom (which contains tokens for all ancestors)
222 for (let i = 0; i < NodeInjectorOffset.BLOOM_SIZE; i++) {
223 lView[injectorIndex + i] = parentLView[parentIndex + i] | parentData[parentIndex + i];
224 }
225 }
226
227 lView[injectorIndex + NodeInjectorOffset.PARENT] = parentLoc;
228 return injectorIndex;
229}
230
231function insertBloom(arr: any[], footer: TNode | null): void {
232 arr.push(0, 0, 0, 0, 0, 0, 0, 0, footer);

Callers 4

di_spec.tsFile · 0.90
resolveProviderFunction · 0.90
initializeDirectivesFunction · 0.90
instantiateAllDirectivesFunction · 0.90

Calls 6

hasParentInjectorFunction · 0.90
getParentInjectorIndexFunction · 0.90
getParentInjectorViewFunction · 0.90
getInjectorIndexFunction · 0.85
insertBloomFunction · 0.85

Tested by

no test coverage detected