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 | /**
|
---|
9 | * Used to resolve resource URLs on `@Component` when used with JIT compilation.
|
---|
10 | *
|
---|
11 | * Example:
|
---|
12 | * ```
|
---|
13 | * @Component({
|
---|
14 | * selector: 'my-comp',
|
---|
15 | * templateUrl: 'my-comp.html', // This requires asynchronous resolution
|
---|
16 | * })
|
---|
17 | * class MyComponent{
|
---|
18 | * }
|
---|
19 | *
|
---|
20 | * // Calling `renderComponent` will fail because `renderComponent` is a synchronous process
|
---|
21 | * // and `MyComponent`'s `@Component.templateUrl` needs to be resolved asynchronously.
|
---|
22 | *
|
---|
23 | * // Calling `resolveComponentResources()` will resolve `@Component.templateUrl` into
|
---|
24 | * // `@Component.template`, which allows `renderComponent` to proceed in a synchronous manner.
|
---|
25 | *
|
---|
26 | * // Use browser's `fetch()` function as the default resource resolution strategy.
|
---|
27 | * resolveComponentResources(fetch).then(() => {
|
---|
28 | * // After resolution all URLs have been converted into `template` strings.
|
---|
29 | * renderComponent(MyComponent);
|
---|
30 | * });
|
---|
31 | *
|
---|
32 | * ```
|
---|
33 | *
|
---|
34 | * NOTE: In AOT the resolution happens during compilation, and so there should be no need
|
---|
35 | * to call this method outside JIT mode.
|
---|
36 | *
|
---|
37 | * @param resourceResolver a function which is responsible for returning a `Promise` to the
|
---|
38 | * contents of the resolved URL. Browser's `fetch()` method is a good default implementation.
|
---|
39 | */
|
---|
40 | export function resolveComponentResources(resourceResolver) {
|
---|
41 | // Store all promises which are fetching the resources.
|
---|
42 | const componentResolved = [];
|
---|
43 | // Cache so that we don't fetch the same resource more than once.
|
---|
44 | const urlMap = new Map();
|
---|
45 | function cachedResourceResolve(url) {
|
---|
46 | let promise = urlMap.get(url);
|
---|
47 | if (!promise) {
|
---|
48 | const resp = resourceResolver(url);
|
---|
49 | urlMap.set(url, promise = resp.then(unwrapResponse));
|
---|
50 | }
|
---|
51 | return promise;
|
---|
52 | }
|
---|
53 | componentResourceResolutionQueue.forEach((component, type) => {
|
---|
54 | const promises = [];
|
---|
55 | if (component.templateUrl) {
|
---|
56 | promises.push(cachedResourceResolve(component.templateUrl).then((template) => {
|
---|
57 | component.template = template;
|
---|
58 | }));
|
---|
59 | }
|
---|
60 | const styleUrls = component.styleUrls;
|
---|
61 | const styles = component.styles || (component.styles = []);
|
---|
62 | const styleOffset = component.styles.length;
|
---|
63 | styleUrls && styleUrls.forEach((styleUrl, index) => {
|
---|
64 | styles.push(''); // pre-allocate array.
|
---|
65 | promises.push(cachedResourceResolve(styleUrl).then((style) => {
|
---|
66 | styles[styleOffset + index] = style;
|
---|
67 | styleUrls.splice(styleUrls.indexOf(styleUrl), 1);
|
---|
68 | if (styleUrls.length == 0) {
|
---|
69 | component.styleUrls = undefined;
|
---|
70 | }
|
---|
71 | }));
|
---|
72 | });
|
---|
73 | const fullyResolved = Promise.all(promises).then(() => componentDefResolved(type));
|
---|
74 | componentResolved.push(fullyResolved);
|
---|
75 | });
|
---|
76 | clearResolutionOfComponentResourcesQueue();
|
---|
77 | return Promise.all(componentResolved).then(() => undefined);
|
---|
78 | }
|
---|
79 | let componentResourceResolutionQueue = new Map();
|
---|
80 | // Track when existing ɵcmp for a Type is waiting on resources.
|
---|
81 | const componentDefPendingResolution = new Set();
|
---|
82 | export function maybeQueueResolutionOfComponentResources(type, metadata) {
|
---|
83 | if (componentNeedsResolution(metadata)) {
|
---|
84 | componentResourceResolutionQueue.set(type, metadata);
|
---|
85 | componentDefPendingResolution.add(type);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | export function isComponentDefPendingResolution(type) {
|
---|
89 | return componentDefPendingResolution.has(type);
|
---|
90 | }
|
---|
91 | export function componentNeedsResolution(component) {
|
---|
92 | return !!((component.templateUrl && !component.hasOwnProperty('template')) ||
|
---|
93 | component.styleUrls && component.styleUrls.length);
|
---|
94 | }
|
---|
95 | export function clearResolutionOfComponentResourcesQueue() {
|
---|
96 | const old = componentResourceResolutionQueue;
|
---|
97 | componentResourceResolutionQueue = new Map();
|
---|
98 | return old;
|
---|
99 | }
|
---|
100 | export function restoreComponentResolutionQueue(queue) {
|
---|
101 | componentDefPendingResolution.clear();
|
---|
102 | queue.forEach((_, type) => componentDefPendingResolution.add(type));
|
---|
103 | componentResourceResolutionQueue = queue;
|
---|
104 | }
|
---|
105 | export function isComponentResourceResolutionQueueEmpty() {
|
---|
106 | return componentResourceResolutionQueue.size === 0;
|
---|
107 | }
|
---|
108 | function unwrapResponse(response) {
|
---|
109 | return typeof response == 'string' ? response : response.text();
|
---|
110 | }
|
---|
111 | function componentDefResolved(type) {
|
---|
112 | componentDefPendingResolution.delete(type);
|
---|
113 | }
|
---|
114 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzb3VyY2VfbG9hZGluZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvcmUvc3JjL21ldGFkYXRhL3Jlc291cmNlX2xvYWRpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBTUg7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0ErQkc7QUFDSCxNQUFNLFVBQVUseUJBQXlCLENBQ3JDLGdCQUE4RTtJQUNoRix1REFBdUQ7SUFDdkQsTUFBTSxpQkFBaUIsR0FBb0IsRUFBRSxDQUFDO0lBRTlDLGlFQUFpRTtJQUNqRSxNQUFNLE1BQU0sR0FBRyxJQUFJLEdBQUcsRUFBMkIsQ0FBQztJQUNsRCxTQUFTLHFCQUFxQixDQUFDLEdBQVc7UUFDeEMsSUFBSSxPQUFPLEdBQUcsTUFBTSxDQUFDLEdBQUcsQ0FBQyxH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