source: trip-planner-front/node_modules/@angular/router/esm2015/src/utils/preactivation.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 22.4 KB
Line 
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 */
8import { equalParamsAndUrlSegments } from '../router_state';
9import { equalPath } from '../url_tree';
10import { forEach, shallowEqual } from '../utils/collection';
11import { nodeChildrenAsMap } from '../utils/tree';
12export class CanActivate {
13 constructor(path) {
14 this.path = path;
15 this.route = this.path[this.path.length - 1];
16 }
17}
18export class CanDeactivate {
19 constructor(component, route) {
20 this.component = component;
21 this.route = route;
22 }
23}
24export function getAllRouteGuards(future, curr, parentContexts) {
25 const futureRoot = future._root;
26 const currRoot = curr ? curr._root : null;
27 return getChildRouteGuards(futureRoot, currRoot, parentContexts, [futureRoot.value]);
28}
29export function getCanActivateChild(p) {
30 const canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null;
31 if (!canActivateChild || canActivateChild.length === 0)
32 return null;
33 return { node: p, guards: canActivateChild };
34}
35export function getToken(token, snapshot, moduleInjector) {
36 const config = getClosestLoadedConfig(snapshot);
37 const injector = config ? config.module.injector : moduleInjector;
38 return injector.get(token);
39}
40function getClosestLoadedConfig(snapshot) {
41 if (!snapshot)
42 return null;
43 for (let s = snapshot.parent; s; s = s.parent) {
44 const route = s.routeConfig;
45 if (route && route._loadedConfig)
46 return route._loadedConfig;
47 }
48 return null;
49}
50function getChildRouteGuards(futureNode, currNode, contexts, futurePath, checks = {
51 canDeactivateChecks: [],
52 canActivateChecks: []
53}) {
54 const prevChildren = nodeChildrenAsMap(currNode);
55 // Process the children of the future route
56 futureNode.children.forEach(c => {
57 getRouteGuards(c, prevChildren[c.value.outlet], contexts, futurePath.concat([c.value]), checks);
58 delete prevChildren[c.value.outlet];
59 });
60 // Process any children left from the current route (not active for the future route)
61 forEach(prevChildren, (v, k) => deactivateRouteAndItsChildren(v, contexts.getContext(k), checks));
62 return checks;
63}
64function getRouteGuards(futureNode, currNode, parentContexts, futurePath, checks = {
65 canDeactivateChecks: [],
66 canActivateChecks: []
67}) {
68 const future = futureNode.value;
69 const curr = currNode ? currNode.value : null;
70 const context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null;
71 // reusing the node
72 if (curr && future.routeConfig === curr.routeConfig) {
73 const shouldRun = shouldRunGuardsAndResolvers(curr, future, future.routeConfig.runGuardsAndResolvers);
74 if (shouldRun) {
75 checks.canActivateChecks.push(new CanActivate(futurePath));
76 }
77 else {
78 // we need to set the data
79 future.data = curr.data;
80 future._resolvedData = curr._resolvedData;
81 }
82 // If we have a component, we need to go through an outlet.
83 if (future.component) {
84 getChildRouteGuards(futureNode, currNode, context ? context.children : null, futurePath, checks);
85 // if we have a componentless route, we recurse but keep the same outlet map.
86 }
87 else {
88 getChildRouteGuards(futureNode, currNode, parentContexts, futurePath, checks);
89 }
90 if (shouldRun && context && context.outlet && context.outlet.isActivated) {
91 checks.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, curr));
92 }
93 }
94 else {
95 if (curr) {
96 deactivateRouteAndItsChildren(currNode, context, checks);
97 }
98 checks.canActivateChecks.push(new CanActivate(futurePath));
99 // If we have a component, we need to go through an outlet.
100 if (future.component) {
101 getChildRouteGuards(futureNode, null, context ? context.children : null, futurePath, checks);
102 // if we have a componentless route, we recurse but keep the same outlet map.
103 }
104 else {
105 getChildRouteGuards(futureNode, null, parentContexts, futurePath, checks);
106 }
107 }
108 return checks;
109}
110function shouldRunGuardsAndResolvers(curr, future, mode) {
111 if (typeof mode === 'function') {
112 return mode(curr, future);
113 }
114 switch (mode) {
115 case 'pathParamsChange':
116 return !equalPath(curr.url, future.url);
117 case 'pathParamsOrQueryParamsChange':
118 return !equalPath(curr.url, future.url) ||
119 !shallowEqual(curr.queryParams, future.queryParams);
120 case 'always':
121 return true;
122 case 'paramsOrQueryParamsChange':
123 return !equalParamsAndUrlSegments(curr, future) ||
124 !shallowEqual(curr.queryParams, future.queryParams);
125 case 'paramsChange':
126 default:
127 return !equalParamsAndUrlSegments(curr, future);
128 }
129}
130function deactivateRouteAndItsChildren(route, context, checks) {
131 const children = nodeChildrenAsMap(route);
132 const r = route.value;
133 forEach(children, (node, childName) => {
134 if (!r.component) {
135 deactivateRouteAndItsChildren(node, context, checks);
136 }
137 else if (context) {
138 deactivateRouteAndItsChildren(node, context.children.getContext(childName), checks);
139 }
140 else {
141 deactivateRouteAndItsChildren(node, null, checks);
142 }
143 });
144 if (!r.component) {
145 checks.canDeactivateChecks.push(new CanDeactivate(null, r));
146 }
147 else if (context && context.outlet && context.outlet.isActivated) {
148 checks.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, r));
149 }
150 else {
151 checks.canDeactivateChecks.push(new CanDeactivate(null, r));
152 }
153}
154//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJlYWN0aXZhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvdXRpbHMvcHJlYWN0aXZhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFNSCxPQUFPLEVBQXlCLHlCQUF5QixFQUFzQixNQUFNLGlCQUFpQixDQUFDO0FBQ3ZHLE9BQU8sRUFBQyxTQUFTLEVBQUMsTUFBTSxhQUFhLENBQUM7QUFDdEMsT0FBTyxFQUFDLE9BQU8sRUFBRSxZQUFZLEVBQUMsTUFBTSxxQkFBcUIsQ0FBQztBQUMxRCxPQUFPLEVBQUMsaUJBQWlCLEVBQVcsTUFBTSxlQUFlLENBQUM7QUFFMUQsTUFBTSxPQUFPLFdBQVc7SUFFdEIsWUFBbUIsSUFBOEI7UUFBOUIsU0FBS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obm9kZSwgbnVsbCwgY2hlY2tzKTtcbiAgICB9XG4gIH0pO1xuXG4gIGlmICghci5jb21wb25lbnQpIHtcbiAgICBjaGVja3MuY2FuRGVhY3RpdmF0ZUNoZWNrcy5wdXNoKG5ldyBDYW5EZWFjdGl2YXRlKG51bGwsIHIpKTtcbiAgfSBlbHNlIGlmIChjb250ZXh0ICYmIGNvbnRleHQub3V0bGV0ICYmIGNvbnRleHQub3V0bGV0LmlzQWN0aXZhdGVkKSB7XG4gICAgY2hlY2tzLmNhbkRlYWN0aXZhdGVDaGVja3MucHVzaChuZXcgQ2FuRGVhY3RpdmF0ZShjb250ZXh0Lm91dGxldC5jb21wb25lbnQsIHIpKTtcbiAgfSBlbHNlIHtcbiAgICBjaGVja3MuY2FuRGVhY3RpdmF0ZUNoZWNrcy5wdXNoKG5ldyBDYW5EZWFjdGl2YXRlKG51bGwsIHIpKTtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.