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 { resolveForwardRef } from '../di/forward_ref';
|
---|
9 | import { Injector } from '../di/injector';
|
---|
10 | import { setCurrentInjector } from '../di/injector_compatibility';
|
---|
11 | import { INJECTOR } from '../di/injector_token';
|
---|
12 | import { getInjectableDef } from '../di/interface/defs';
|
---|
13 | import { INJECTOR_SCOPE } from '../di/scope';
|
---|
14 | import { NgModuleRef } from '../linker/ng_module_factory';
|
---|
15 | import { newArray } from '../util/array_utils';
|
---|
16 | import { stringify } from '../util/stringify';
|
---|
17 | import { splitDepsDsl, tokenKey } from './util';
|
---|
18 | const UNDEFINED_VALUE = {};
|
---|
19 | const InjectorRefTokenKey = tokenKey(Injector);
|
---|
20 | const INJECTORRefTokenKey = tokenKey(INJECTOR);
|
---|
21 | const NgModuleRefTokenKey = tokenKey(NgModuleRef);
|
---|
22 | export function moduleProvideDef(flags, token, value, deps) {
|
---|
23 | // Need to resolve forwardRefs as e.g. for `useValue` we
|
---|
24 | // lowered the expression and then stopped evaluating it,
|
---|
25 | // i.e. also didn't unwrap it.
|
---|
26 | value = resolveForwardRef(value);
|
---|
27 | const depDefs = splitDepsDsl(deps, stringify(token));
|
---|
28 | return {
|
---|
29 | // will bet set by the module definition
|
---|
30 | index: -1,
|
---|
31 | deps: depDefs,
|
---|
32 | flags,
|
---|
33 | token,
|
---|
34 | value
|
---|
35 | };
|
---|
36 | }
|
---|
37 | export function moduleDef(providers) {
|
---|
38 | const providersByKey = {};
|
---|
39 | const modules = [];
|
---|
40 | let scope = null;
|
---|
41 | for (let i = 0; i < providers.length; i++) {
|
---|
42 | const provider = providers[i];
|
---|
43 | if (provider.token === INJECTOR_SCOPE) {
|
---|
44 | scope = provider.value;
|
---|
45 | }
|
---|
46 | if (provider.flags & 1073741824 /* TypeNgModule */) {
|
---|
47 | modules.push(provider.token);
|
---|
48 | }
|
---|
49 | provider.index = i;
|
---|
50 | providersByKey[tokenKey(provider.token)] = provider;
|
---|
51 | }
|
---|
52 | return {
|
---|
53 | // Will be filled later...
|
---|
54 | factory: null,
|
---|
55 | providersByKey,
|
---|
56 | providers,
|
---|
57 | modules,
|
---|
58 | scope: scope,
|
---|
59 | };
|
---|
60 | }
|
---|
61 | export function initNgModule(data) {
|
---|
62 | const def = data._def;
|
---|
63 | const providers = data._providers = newArray(def.providers.length);
|
---|
64 | for (let i = 0; i < def.providers.length; i++) {
|
---|
65 | const provDef = def.providers[i];
|
---|
66 | if (!(provDef.flags & 4096 /* LazyProvider */)) {
|
---|
67 | // Make sure the provider has not been already initialized outside this loop.
|
---|
68 | if (providers[i] === undefined) {
|
---|
69 | providers[i] = _createProviderInstance(data, provDef);
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | export function resolveNgModuleDep(data, depDef, notFoundValue = Injector.THROW_IF_NOT_FOUND) {
|
---|
75 | const former = setCurrentInjector(data);
|
---|
76 | try {
|
---|
77 | if (depDef.flags & 8 /* Value */) {
|
---|
78 | return depDef.token;
|
---|
79 | }
|
---|
80 | if (depDef.flags & 2 /* Optional */) {
|
---|
81 | notFoundValue = null;
|
---|
82 | }
|
---|
83 | if (depDef.flags & 1 /* SkipSelf */) {
|
---|
84 | return data._parent.get(depDef.token, notFoundValue);
|
---|
85 | }
|
---|
86 | const tokenKey = depDef.tokenKey;
|
---|
87 | switch (tokenKey) {
|
---|
88 | case InjectorRefTokenKey:
|
---|
89 | case INJECTORRefTokenKey:
|
---|
90 | case NgModuleRefTokenKey:
|
---|
91 | return data;
|
---|
92 | }
|
---|
93 | const providerDef = data._def.providersByKey[tokenKey];
|
---|
94 | let injectableDef;
|
---|
95 | if (providerDef) {
|
---|
96 | let providerInstance = data._providers[providerDef.index];
|
---|
97 | if (providerInstance === undefined) {
|
---|
98 | providerInstance = data._providers[providerDef.index] =
|
---|
99 | _createProviderInstance(data, providerDef);
|
---|
100 | }
|
---|
101 | return providerInstance === UNDEFINED_VALUE ? undefined : providerInstance;
|
---|
102 | }
|
---|
103 | else if ((injectableDef = getInjectableDef(depDef.token)) && targetsModule(data, injectableDef)) {
|
---|
104 | const index = data._providers.length;
|
---|
105 | data._def.providers[index] = data._def.providersByKey[depDef.tokenKey] = {
|
---|
106 | flags: 1024 /* TypeFactoryProvider */ | 4096 /* LazyProvider */,
|
---|
107 | value: injectableDef.factory,
|
---|
108 | deps: [],
|
---|
109 | index,
|
---|
110 | token: depDef.token,
|
---|
111 | };
|
---|
112 | data._providers[index] = UNDEFINED_VALUE;
|
---|
113 | return (data._providers[index] =
|
---|
114 | _createProviderInstance(data, data._def.providersByKey[depDef.tokenKey]));
|
---|
115 | }
|
---|
116 | else if (depDef.flags & 4 /* Self */) {
|
---|
117 | return notFoundValue;
|
---|
118 | }
|
---|
119 | return data._parent.get(depDef.token, notFoundValue);
|
---|
120 | }
|
---|
121 | finally {
|
---|
122 | setCurrentInjector(former);
|
---|
123 | }
|
---|
124 | }
|
---|
125 | function moduleTransitivelyPresent(ngModule, scope) {
|
---|
126 | return ngModule._def.modules.indexOf(scope) > -1;
|
---|
127 | }
|
---|
128 | function targetsModule(ngModule, def) {
|
---|
129 | const providedIn = resolveForwardRef(def.providedIn);
|
---|
130 | return providedIn != null &&
|
---|
131 | (providedIn === 'any' || providedIn === ngModule._def.scope ||
|
---|
132 | moduleTransitivelyPresent(ngModule, providedIn));
|
---|
133 | }
|
---|
134 | function _createProviderInstance(ngModule, providerDef) {
|
---|
135 | let injectable;
|
---|
136 | switch (providerDef.flags & 201347067 /* Types */) {
|
---|
137 | case 512 /* TypeClassProvider */:
|
---|
138 | injectable = _createClass(ngModule, providerDef.value, providerDef.deps);
|
---|
139 | break;
|
---|
140 | case 1024 /* TypeFactoryProvider */:
|
---|
141 | injectable = _callFactory(ngModule, providerDef.value, providerDef.deps);
|
---|
142 | break;
|
---|
143 | case 2048 /* TypeUseExistingProvider */:
|
---|
144 | injectable = resolveNgModuleDep(ngModule, providerDef.deps[0]);
|
---|
145 | break;
|
---|
146 | case 256 /* TypeValueProvider */:
|
---|
147 | injectable = providerDef.value;
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | // The read of `ngOnDestroy` here is slightly expensive as it's megamorphic, so it should be
|
---|
151 | // avoided if possible. The sequence of checks here determines whether ngOnDestroy needs to be
|
---|
152 | // checked. It might not if the `injectable` isn't an object or if NodeFlags.OnDestroy is already
|
---|
153 | // set (ngOnDestroy was detected statically).
|
---|
154 | if (injectable !== UNDEFINED_VALUE && injectable !== null && typeof injectable === 'object' &&
|
---|
155 | !(providerDef.flags & 131072 /* OnDestroy */) && typeof injectable.ngOnDestroy === 'function') {
|
---|
156 | providerDef.flags |= 131072 /* OnDestroy */;
|
---|
157 | }
|
---|
158 | return injectable === undefined ? UNDEFINED_VALUE : injectable;
|
---|
159 | }
|
---|
160 | function _createClass(ngModule, ctor, deps) {
|
---|
161 | const len = deps.length;
|
---|
162 | switch (len) {
|
---|
163 | case 0:
|
---|
164 | return new ctor();
|
---|
165 | case 1:
|
---|
166 | return new ctor(resolveNgModuleDep(ngModule, deps[0]));
|
---|
167 | case 2:
|
---|
168 | return new ctor(resolveNgModuleDep(ngModule, deps[0]), resolveNgModuleDep(ngModule, deps[1]));
|
---|
169 | case 3:
|
---|
170 | return new ctor(resolveNgModuleDep(ngModule, deps[0]), resolveNgModuleDep(ngModule, deps[1]), resolveNgModuleDep(ngModule, deps[2]));
|
---|
171 | default:
|
---|
172 | const depValues = [];
|
---|
173 | for (let i = 0; i < len; i++) {
|
---|
174 | depValues[i] = resolveNgModuleDep(ngModule, deps[i]);
|
---|
175 | }
|
---|
176 | return new ctor(...depValues);
|
---|
177 | }
|
---|
178 | }
|
---|
179 | function _callFactory(ngModule, factory, deps) {
|
---|
180 | const len = deps.length;
|
---|
181 | switch (len) {
|
---|
182 | case 0:
|
---|
183 | return factory();
|
---|
184 | case 1:
|
---|
185 | return factory(resolveNgModuleDep(ngModule, deps[0]));
|
---|
186 | case 2:
|
---|
187 | return factory(resolveNgModuleDep(ngModule, deps[0]), resolveNgModuleDep(ngModule, deps[1]));
|
---|
188 | case 3:
|
---|
189 | return factory(resolveNgModuleDep(ngModule, deps[0]), resolveNgModuleDep(ngModule, deps[1]), resolveNgModuleDep(ngModule, deps[2]));
|
---|
190 | default:
|
---|
191 | const depValues = [];
|
---|
192 | for (let i = 0; i < len; i++) {
|
---|
193 | depValues[i] = resolveNgModuleDep(ngModule, deps[i]);
|
---|
194 | }
|
---|
195 | return factory(...depValues);
|
---|
196 | }
|
---|
197 | }
|
---|
198 | export function callNgModuleLifecycle(ngModule, lifecycles) {
|
---|
199 | const def = ngModule._def;
|
---|
200 | const destroyed = new Set();
|
---|
201 | for (let i = 0; i < def.providers.length; i++) {
|
---|
202 | const provDef = def.providers[i];
|
---|
203 | if (provDef.flags & 131072 /* OnDestroy */) {
|
---|
204 | const instance = ngModule._providers[i];
|
---|
205 | if (instance && instance !== UNDEFINED_VALUE) {
|
---|
206 | const onDestroy = instance.ngOnDestroy;
|
---|
207 | if (typeof onDestroy === 'function' && !destroyed.has(instance)) {
|
---|
208 | onDestroy.apply(instance);
|
---|
209 | destroyed.add(instance);
|
---|
210 | }
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdfbW9kdWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29yZS9zcmMvdmlldy9uZ19tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLGlCQUFpQixFQUFDLE1BQU0sbUJBQW1CLENBQUM7QUFDcEQsT0FBTyxFQ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