1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var _require = require('./loadQuery'),
|
14 | loadQuery = _require.loadQuery;
|
15 |
|
16 | function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
|
17 |
|
18 | var loadingPromise = null;
|
19 |
|
20 | if (entryPoint.root.getModuleIfRequired() == null) {
|
21 | loadingPromise = entryPoint.root.load();
|
22 | }
|
23 |
|
24 | var preloadProps = entryPoint.getPreloadProps(entryPointParams);
|
25 | var queries = preloadProps.queries,
|
26 | entryPoints = preloadProps.entryPoints,
|
27 | extraProps = preloadProps.extraProps;
|
28 | var preloadedQueries = {};
|
29 | var preloadedEntryPoints = {};
|
30 |
|
31 | if (queries != null) {
|
32 | var queriesPropNames = Object.keys(queries);
|
33 | queriesPropNames.forEach(function (queryPropName) {
|
34 | var _queries$queryPropNam = queries[queryPropName],
|
35 | environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
|
36 | options = _queries$queryPropNam.options,
|
37 | parameters = _queries$queryPropNam.parameters,
|
38 | variables = _queries$queryPropNam.variables;
|
39 | var environment = environmentProvider.getEnvironment(environmentProviderOptions);
|
40 | preloadedQueries[queryPropName] = loadQuery(environment, parameters, variables, {
|
41 | fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
42 | networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig
|
43 | }, environmentProviderOptions);
|
44 | });
|
45 | }
|
46 |
|
47 | if (entryPoints != null) {
|
48 | var entryPointPropNames = Object.keys(entryPoints);
|
49 | entryPointPropNames.forEach(function (entryPointPropName) {
|
50 | var entryPointDescription = entryPoints[entryPointPropName];
|
51 |
|
52 | if (entryPointDescription == null) {
|
53 | return;
|
54 | }
|
55 |
|
56 | var nestedEntryPoint = entryPointDescription.entryPoint,
|
57 | nestedParams = entryPointDescription.entryPointParams;
|
58 | preloadedEntryPoints[entryPointPropName] = loadEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
|
59 | });
|
60 | }
|
61 |
|
62 | var dispose = function dispose() {
|
63 | if (preloadedQueries != null) {
|
64 | Object.values(preloadedQueries).forEach(function (_ref) {
|
65 | var innerDispose = _ref.dispose;
|
66 | innerDispose();
|
67 | });
|
68 | }
|
69 | };
|
70 |
|
71 | return {
|
72 | dispose: dispose,
|
73 | entryPoints: preloadedEntryPoints,
|
74 | extraProps: extraProps !== null && extraProps !== void 0 ? extraProps : null,
|
75 | getComponent: function getComponent() {
|
76 | var component = entryPoint.root.getModuleIfRequired();
|
77 |
|
78 | if (component == null) {
|
79 | var _loadingPromise;
|
80 |
|
81 | loadingPromise = (_loadingPromise = loadingPromise) !== null && _loadingPromise !== void 0 ? _loadingPromise : entryPoint.root.load();
|
82 | throw loadingPromise;
|
83 | }
|
84 |
|
85 |
|
86 | return component;
|
87 | },
|
88 | queries: preloadedQueries
|
89 | };
|
90 | }
|
91 |
|
92 | module.exports = loadEntryPoint; |
\ | No newline at end of file |