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