1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.clearImportedCache = exports.getLoadable = exports.executeLoadable = exports.dryRender = void 0;
|
4 | var signatures_1 = require("../utils/signatures");
|
5 | var pending_1 = require("./pending");
|
6 | var registry_1 = require("./registry");
|
7 | var toLoadable_1 = require("./toLoadable");
|
8 | var utils_1 = require("./utils");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var dryRender = function (renderFunction) {
|
14 | renderFunction();
|
15 | return Promise.resolve().then(pending_1.done);
|
16 | };
|
17 | exports.dryRender = dryRender;
|
18 | function executeLoadable(importFunction) {
|
19 | if ('resolution' in importFunction) {
|
20 | return importFunction.reload();
|
21 | }
|
22 | else {
|
23 | return importFunction();
|
24 | }
|
25 | }
|
26 | exports.executeLoadable = executeLoadable;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function getLoadable(importFunction) {
|
33 | if ('resolution' in importFunction) {
|
34 | return importFunction;
|
35 | }
|
36 | if (registry_1.LOADABLE_WEAK_SIGNATURE.has(importFunction)) {
|
37 | return registry_1.LOADABLE_WEAK_SIGNATURE.get(importFunction);
|
38 | }
|
39 | var rawSignature = (0, signatures_1.getFunctionSignature)(importFunction);
|
40 | var ownMark = (0, signatures_1.importMatch)(String(rawSignature));
|
41 |
|
42 | var functionSignature = (0, utils_1.toKnownSignature)(rawSignature, ownMark);
|
43 | if (registry_1.LOADABLE_SIGNATURE.has(functionSignature)) {
|
44 |
|
45 | var loadable_1 = registry_1.LOADABLE_SIGNATURE.get(functionSignature);
|
46 | loadable_1.replaceImportFunction(importFunction);
|
47 | return loadable_1;
|
48 | }
|
49 | if (ownMark) {
|
50 | if (process.env.NODE_ENV !== 'production') {
|
51 | if (ownMark.length > 1) {
|
52 |
|
53 | console.warn('A function exposes multiple imports. Imported-Components cannot know which one will be used.', {
|
54 | importFunction: importFunction,
|
55 | });
|
56 | }
|
57 | }
|
58 | registry_1.LOADABLE_SIGNATURE.forEach(function (_a) {
|
59 | var mark = _a.mark, importer = _a.importer;
|
60 | if (mark[0] === ownMark[1] && mark.join('|') === ownMark.join('|')) {
|
61 |
|
62 | console.warn("Another loadable found for an existing mark. That's possible, but signatures must match (https://github.com/theKashey/react-imported-component/issues/192):", {
|
63 | mark: mark,
|
64 | knownImporter: importer,
|
65 | currentImported: importFunction,
|
66 | currentSignature: String(importFunction),
|
67 | knownSignature: String(importer),
|
68 | });
|
69 | }
|
70 | });
|
71 | }
|
72 | var loadable = (0, toLoadable_1.toLoadable)(importFunction);
|
73 | registry_1.LOADABLE_WEAK_SIGNATURE.set(importFunction, loadable);
|
74 | return loadable;
|
75 | }
|
76 | exports.getLoadable = getLoadable;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var clearImportedCache = function () { return registry_1.LOADABLE_SIGNATURE.clear(); };
|
82 | exports.clearImportedCache = clearImportedCache;
|