( tView: TView, lView: LView, context: any, cleanupFn: Function, )
| 335 | * - Index of context we just saved in LView.cleanupInstances |
| 336 | */ |
| 337 | export function storeCleanupWithContext( |
| 338 | tView: TView, |
| 339 | lView: LView, |
| 340 | context: any, |
| 341 | cleanupFn: Function, |
| 342 | ): void { |
| 343 | const lCleanup = getOrCreateLViewCleanup(lView); |
| 344 | |
| 345 | // Historically the `storeCleanupWithContext` was used to register both framework-level and |
| 346 | // user-defined cleanup callbacks, but over time those two types of cleanups were separated. |
| 347 | // This dev mode checks assures that user-level cleanup callbacks are _not_ stored in data |
| 348 | // structures reserved for framework-specific hooks. |
| 349 | ngDevMode && |
| 350 | assertDefined( |
| 351 | context, |
| 352 | 'Cleanup context is mandatory when registering framework-level destroy hooks', |
| 353 | ); |
| 354 | lCleanup.push(context); |
| 355 | |
| 356 | if (tView.firstCreatePass) { |
| 357 | getOrCreateTViewCleanup(tView).push(cleanupFn, lCleanup.length - 1); |
| 358 | } else { |
| 359 | // Make sure that no new framework-level cleanup functions are registered after the first |
| 360 | // template pass is done (and TView data structures are meant to fully constructed). |
| 361 | if (ngDevMode) { |
| 362 | Object.freeze(getOrCreateTViewCleanup(tView)); |
| 363 | } |
| 364 | } |
| 365 | } |
no test coverage detected
searching dependent graphs…