( paramsInheritanceStrategy: 'emptyOnly' | 'always', )
| 26 | import {DefaultUrlSerializer} from '../url_tree'; |
| 27 | |
| 28 | export function resolveData( |
| 29 | paramsInheritanceStrategy: 'emptyOnly' | 'always', |
| 30 | ): MonoTypeOperatorFunction<NavigationTransition> { |
| 31 | return mergeMap((t) => { |
| 32 | const { |
| 33 | targetSnapshot, |
| 34 | guards: {canActivateChecks}, |
| 35 | } = t; |
| 36 | |
| 37 | if (!canActivateChecks.length) { |
| 38 | return of(t); |
| 39 | } |
| 40 | // Iterating a Set in javascript happens in insertion order so it is safe to use a `Set` to |
| 41 | // preserve the correct order that the resolvers should run in. |
| 42 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#description |
| 43 | const routesWithResolversToRun = new Set(canActivateChecks.map((check) => check.route)); |
| 44 | const routesNeedingDataUpdates = new Set<ActivatedRouteSnapshot>(); |
| 45 | for (const route of routesWithResolversToRun) { |
| 46 | if (routesNeedingDataUpdates.has(route)) { |
| 47 | continue; |
| 48 | } |
| 49 | // All children under the route with a resolver to run need to recompute inherited data. |
| 50 | for (const newRoute of flattenRouteTree(route)) { |
| 51 | routesNeedingDataUpdates.add(newRoute); |
| 52 | } |
| 53 | } |
| 54 | let routesProcessed = 0; |
| 55 | return from(routesNeedingDataUpdates).pipe( |
| 56 | concatMap((route) => { |
| 57 | if (routesWithResolversToRun.has(route)) { |
| 58 | return runResolve(route, targetSnapshot!, paramsInheritanceStrategy); |
| 59 | } else { |
| 60 | route.data = getInherited(route, route.parent, paramsInheritanceStrategy).resolve; |
| 61 | return of(void 0); |
| 62 | } |
| 63 | }), |
| 64 | tap(() => routesProcessed++), |
| 65 | takeLast(1), |
| 66 | mergeMap((_) => (routesProcessed === routesNeedingDataUpdates.size ? of(t) : EMPTY)), |
| 67 | ); |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the `ActivatedRouteSnapshot` tree as an array, using DFS to traverse the route tree. |
no test coverage detected
searching dependent graphs…