1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { EMPTY, from, of } from 'rxjs';
|
---|
9 | import { concatMap, map, mergeMap, takeLast, tap } from 'rxjs/operators';
|
---|
10 | import { inheritedParamsDataResolve } from '../router_state';
|
---|
11 | import { wrapIntoObservable } from '../utils/collection';
|
---|
12 | import { getToken } from '../utils/preactivation';
|
---|
13 | export function resolveData(paramsInheritanceStrategy, moduleInjector) {
|
---|
14 | return mergeMap(t => {
|
---|
15 | const { targetSnapshot, guards: { canActivateChecks } } = t;
|
---|
16 | if (!canActivateChecks.length) {
|
---|
17 | return of(t);
|
---|
18 | }
|
---|
19 | let canActivateChecksResolved = 0;
|
---|
20 | return from(canActivateChecks)
|
---|
21 | .pipe(concatMap(check => runResolve(check.route, targetSnapshot, paramsInheritanceStrategy, moduleInjector)), tap(() => canActivateChecksResolved++), takeLast(1), mergeMap(_ => canActivateChecksResolved === canActivateChecks.length ? of(t) : EMPTY));
|
---|
22 | });
|
---|
23 | }
|
---|
24 | function runResolve(futureARS, futureRSS, paramsInheritanceStrategy, moduleInjector) {
|
---|
25 | const resolve = futureARS._resolve;
|
---|
26 | return resolveNode(resolve, futureARS, futureRSS, moduleInjector)
|
---|
27 | .pipe(map((resolvedData) => {
|
---|
28 | futureARS._resolvedData = resolvedData;
|
---|
29 | futureARS.data = Object.assign(Object.assign({}, futureARS.data), inheritedParamsDataResolve(futureARS, paramsInheritanceStrategy).resolve);
|
---|
30 | return null;
|
---|
31 | }));
|
---|
32 | }
|
---|
33 | function resolveNode(resolve, futureARS, futureRSS, moduleInjector) {
|
---|
34 | const keys = Object.keys(resolve);
|
---|
35 | if (keys.length === 0) {
|
---|
36 | return of({});
|
---|
37 | }
|
---|
38 | const data = {};
|
---|
39 | return from(keys).pipe(mergeMap((key) => getResolver(resolve[key], futureARS, futureRSS, moduleInjector)
|
---|
40 | .pipe(tap((value) => {
|
---|
41 | data[key] = value;
|
---|
42 | }))), takeLast(1), mergeMap(() => {
|
---|
43 | // Ensure all resolvers returned values, otherwise don't emit any "next" and just complete
|
---|
44 | // the chain which will cancel navigation
|
---|
45 | if (Object.keys(data).length === keys.length) {
|
---|
46 | return of(data);
|
---|
47 | }
|
---|
48 | return EMPTY;
|
---|
49 | }));
|
---|
50 | }
|
---|
51 | function getResolver(injectionToken, futureARS, futureRSS, moduleInjector) {
|
---|
52 | const resolver = getToken(injectionToken, futureARS, moduleInjector);
|
---|
53 | return resolver.resolve ? wrapIntoObservable(resolver.resolve(futureARS, futureRSS)) :
|
---|
54 | wrapIntoObservable(resolver(futureARS, futureRSS));
|
---|
55 | }
|
---|
56 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzb2x2ZV9kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvcm91dGVyL3NyYy9vcGVyYXRvcnMvcmVzb2x2ZV9kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUdILE9BQU8sRUFBQyxLQUFLLEVBQUUsSUFBSSxFQUF3QyxFQUFFLEVBQUMsTUFBTSxNQUFNLENBQUM7QUFDM0UsT0FBTyxFQUFDLFNBQVMsRUFBRSxHQUFHLEVBQUUsUUFBUSxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUl2RSxPQUFPLEVBQXlCLDBCQUEwQixFQUFzQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hHLE9BQU8sRUFBQyxrQkFBa0IsRUFBQyxNQUFNLHFCQUFxQixDQUFDO0FBQ3ZELE9BQU8sRUFBQyxRQUFRLEVBQUMsTUFBTSx3QkFBd0Is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