MCPcopy Index your code
hub / github.com/angular/angular / resolveData

Function resolveData

packages/router/src/operators/resolve_data.ts:28–69  ·  view source on GitHub ↗
(
  paramsInheritanceStrategy: 'emptyOnly' | 'always',
)

Source from the content-addressed store, hash-verified

26import {DefaultUrlSerializer} from '../url_tree';
27
28export 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.

Callers 1

setupNavigationsMethod · 0.90

Calls 6

getInheritedFunction · 0.90
flattenRouteTreeFunction · 0.85
runResolveFunction · 0.85
mapMethod · 0.80
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…