@module-federation/data-prefetch 0.6.6 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +1 -1
- package/__tests__/prefetch.spec.ts +3 -2
- package/__tests__/react.spec.ts +1 -1
- package/dist/LICENSE +21 -0
- package/dist/babel.cjs.d.ts +2 -0
- package/dist/babel.cjs.js +62 -0
- package/dist/babel.esm.js +56 -0
- package/dist/cli.cjs.d.ts +1 -0
- package/dist/cli.cjs.js +3579 -0
- package/dist/cli.esm.js +3565 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +15 -0
- package/dist/index.cjs2.js +7 -0
- package/dist/index.esm.js +6 -0
- package/dist/index.esm2.js +5 -0
- package/dist/package.json +99 -0
- package/dist/plugin.cjs.d.ts +2 -0
- package/dist/plugin.cjs.js +362 -0
- package/dist/plugin.esm.js +357 -0
- package/dist/prefetch.cjs.js +351 -0
- package/dist/prefetch.esm.js +349 -0
- package/dist/react.cjs.d.ts +1 -0
- package/dist/react.cjs.js +163 -0
- package/dist/react.esm.js +159 -0
- package/dist/runtime-utils.cjs.js +31 -0
- package/dist/runtime-utils.esm.js +26 -0
- package/dist/shared.cjs.d.ts +2 -0
- package/dist/shared.cjs.js +26 -0
- package/dist/shared.esm.js +24 -0
- package/dist/{cli → src/cli}/babel.d.ts +2 -4
- package/dist/{cli → src/cli}/index.d.ts +5 -8
- package/dist/src/common/constant.d.ts +1 -0
- package/dist/src/common/index.d.ts +1 -0
- package/dist/src/common/node-utils.d.ts +2 -0
- package/dist/src/common/runtime-utils.d.ts +5 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/logger/index.d.ts +3 -0
- package/dist/src/plugin.d.ts +3 -0
- package/dist/{prefetch-4e9646e4.d.ts → src/prefetch.d.ts} +5 -7
- package/dist/src/react/hooks.d.ts +11 -0
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/utils.d.ts +1 -0
- package/dist/src/shared/index.d.ts +3 -0
- package/dist/src/universal/index.d.ts +2 -0
- package/dist/universal.cjs.d.ts +1 -0
- package/dist/universal.cjs.js +38 -0
- package/dist/universal.esm.js +34 -0
- package/jest.config.js +2 -2
- package/package.json +31 -28
- package/project.json +46 -4
- package/rollup.config.js +25 -0
- package/src/cli/index.ts +12 -10
- package/src/prefetch.ts +6 -2
- package/tsconfig.json +1 -1
- package/tsconfig.lib.json +10 -0
- package/dist/cli/babel.js +0 -84
- package/dist/cli/index.js +0 -205
- package/dist/esm/chunk-AJPO2B2T.js +0 -30
- package/dist/esm/chunk-EZUCZHGV.js +0 -11
- package/dist/esm/chunk-ISLXMAIA.js +0 -155
- package/dist/esm/chunk-KI4QGPIS.js +0 -32
- package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
- package/dist/esm/chunk-VVZ6XIM6.js +0 -166
- package/dist/esm/cli/babel.js +0 -57
- package/dist/esm/cli/index.js +0 -178
- package/dist/esm/index.js +0 -13
- package/dist/esm/plugin.js +0 -12
- package/dist/esm/react/index.js +0 -94
- package/dist/esm/shared/index.js +0 -27
- package/dist/esm/universal/index.js +0 -9
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -350
- package/dist/plugin.d.ts +0 -5
- package/dist/plugin.js +0 -346
- package/dist/react/index.d.ts +0 -16
- package/dist/react/index.js +0 -286
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -48
- package/dist/universal/index.d.ts +0 -8
- package/dist/universal/index.js +0 -204
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var prefetch = require('./prefetch.cjs.js');
|
|
6
|
+
var plugin = require('./plugin.cjs.js');
|
|
7
|
+
require('@module-federation/runtime');
|
|
8
|
+
require('@module-federation/sdk');
|
|
9
|
+
require('./runtime-utils.cjs.js');
|
|
10
|
+
require('./index.cjs2.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.MFDataPrefetch = prefetch.MFDataPrefetch;
|
|
15
|
+
exports.prefetchPlugin = plugin.prefetchPlugin;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/data-prefetch",
|
|
3
|
+
"description": "Module Federation Data Prefetch",
|
|
4
|
+
"version": "0.6.7",
|
|
5
|
+
"author": "nieyan <nyqykk@foxmail.com>",
|
|
6
|
+
"homepage": "https://github.com/module-federation/core",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "cross-env WATCH=true tsup",
|
|
10
|
+
"build": "rm -rf dist && tsup",
|
|
11
|
+
"test": "jest"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"types": "./dist/index.cjs.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./react": {
|
|
23
|
+
"import": "./dist/react.esm.js",
|
|
24
|
+
"require": "./dist/react.cjs.js",
|
|
25
|
+
"types": "./dist/react.cjs.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./cli": {
|
|
28
|
+
"import": "./dist/cli.esm.js",
|
|
29
|
+
"require": "./dist/cli.cjs.js",
|
|
30
|
+
"types": "./dist/cli.cjs.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./babel-plugin": {
|
|
33
|
+
"import": "./dist/babel.esm.js",
|
|
34
|
+
"require": "./dist/babel.cjs.js",
|
|
35
|
+
"types": "./dist/babel.cjs.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./universal": {
|
|
38
|
+
"import": "./dist/universal.esm.js",
|
|
39
|
+
"require": "./dist/universal.cjs.js",
|
|
40
|
+
"types": "./dist/universal.cjs.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./shared": {
|
|
43
|
+
"import": "./dist/shared.esm.js",
|
|
44
|
+
"require": "./dist/shared.cjs.js",
|
|
45
|
+
"types": "./dist/shared/.cjs.d.ts"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"typesVersions": {
|
|
49
|
+
"*": {
|
|
50
|
+
".": [
|
|
51
|
+
"./dist/index.cjs.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"react": [
|
|
54
|
+
"./dist/react.cjs.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"cli": [
|
|
57
|
+
"./dist/cli.cjs.d.ts"
|
|
58
|
+
],
|
|
59
|
+
"universal": [
|
|
60
|
+
"./dist/universal.cjs.d.ts"
|
|
61
|
+
],
|
|
62
|
+
"shared": [
|
|
63
|
+
"./dist/shared.cjs.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"babel-plugin": [
|
|
66
|
+
"./dist/babel.cjs.d.ts"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"main": "./index.cjs.js",
|
|
71
|
+
"module": "./index.esm.js",
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"react": ">=16.9.0",
|
|
74
|
+
"react-dom": ">=16.9.0"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
78
|
+
"@types/fs-extra": "9.0.6",
|
|
79
|
+
"@types/jest": "^29.5.11",
|
|
80
|
+
"@types/node": "^17.0.45",
|
|
81
|
+
"@types/react": "~18.0.38",
|
|
82
|
+
"esbuild-plugin-replace": "^1.4.0",
|
|
83
|
+
"jest": "^29.7.0",
|
|
84
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
85
|
+
"minimist": "^1.2.8",
|
|
86
|
+
"react": "^18.2.0",
|
|
87
|
+
"react-dom": "^18.2.0",
|
|
88
|
+
"react-router": "^6.21.3",
|
|
89
|
+
"react-test-renderer": "^18.2.0",
|
|
90
|
+
"ts-jest": "29.0.1",
|
|
91
|
+
"tsup": "6.2.0",
|
|
92
|
+
"webpack": "5.75.0"
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"@module-federation/sdk": "workspace:*",
|
|
96
|
+
"@module-federation/runtime": "workspace:*",
|
|
97
|
+
"fs-extra": "9.1.0"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var sdk = require('@module-federation/sdk');
|
|
6
|
+
var runtimeUtils = require('./runtime-utils.cjs.js');
|
|
7
|
+
var prefetch = require('./prefetch.cjs.js');
|
|
8
|
+
var index = require('./index.cjs2.js');
|
|
9
|
+
require('@module-federation/runtime');
|
|
10
|
+
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
12
|
+
try {
|
|
13
|
+
var info = gen[key](arg);
|
|
14
|
+
var value = info.value;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (info.done) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
} else {
|
|
22
|
+
Promise.resolve(value).then(_next, _throw);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _async_to_generator(fn) {
|
|
26
|
+
return function() {
|
|
27
|
+
var self = this, args = arguments;
|
|
28
|
+
return new Promise(function(resolve, reject) {
|
|
29
|
+
var gen = fn.apply(self, args);
|
|
30
|
+
function _next(value) {
|
|
31
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
32
|
+
}
|
|
33
|
+
function _throw(err) {
|
|
34
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
35
|
+
}
|
|
36
|
+
_next(undefined);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function _instanceof(left, right) {
|
|
41
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
42
|
+
return !!right[Symbol.hasInstance](left);
|
|
43
|
+
} else {
|
|
44
|
+
return left instanceof right;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function _ts_generator(thisArg, body) {
|
|
48
|
+
var f, y, t, g, _ = {
|
|
49
|
+
label: 0,
|
|
50
|
+
sent: function() {
|
|
51
|
+
if (t[0] & 1) throw t[1];
|
|
52
|
+
return t[1];
|
|
53
|
+
},
|
|
54
|
+
trys: [],
|
|
55
|
+
ops: []
|
|
56
|
+
};
|
|
57
|
+
return g = {
|
|
58
|
+
next: verb(0),
|
|
59
|
+
"throw": verb(1),
|
|
60
|
+
"return": verb(2)
|
|
61
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
62
|
+
return this;
|
|
63
|
+
}), g;
|
|
64
|
+
function verb(n) {
|
|
65
|
+
return function(v) {
|
|
66
|
+
return step([
|
|
67
|
+
n,
|
|
68
|
+
v
|
|
69
|
+
]);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function step(op) {
|
|
73
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
74
|
+
while(_)try {
|
|
75
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
76
|
+
if (y = 0, t) op = [
|
|
77
|
+
op[0] & 2,
|
|
78
|
+
t.value
|
|
79
|
+
];
|
|
80
|
+
switch(op[0]){
|
|
81
|
+
case 0:
|
|
82
|
+
case 1:
|
|
83
|
+
t = op;
|
|
84
|
+
break;
|
|
85
|
+
case 4:
|
|
86
|
+
_.label++;
|
|
87
|
+
return {
|
|
88
|
+
value: op[1],
|
|
89
|
+
done: false
|
|
90
|
+
};
|
|
91
|
+
case 5:
|
|
92
|
+
_.label++;
|
|
93
|
+
y = op[1];
|
|
94
|
+
op = [
|
|
95
|
+
0
|
|
96
|
+
];
|
|
97
|
+
continue;
|
|
98
|
+
case 7:
|
|
99
|
+
op = _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
default:
|
|
103
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
104
|
+
_ = 0;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
108
|
+
_.label = op[1];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
112
|
+
_.label = t[1];
|
|
113
|
+
t = op;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (t && _.label < t[2]) {
|
|
117
|
+
_.label = t[2];
|
|
118
|
+
_.ops.push(op);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (t[2]) _.ops.pop();
|
|
122
|
+
_.trys.pop();
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
op = body.call(thisArg, _);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
op = [
|
|
128
|
+
6,
|
|
129
|
+
e
|
|
130
|
+
];
|
|
131
|
+
y = 0;
|
|
132
|
+
} finally{
|
|
133
|
+
f = t = 0;
|
|
134
|
+
}
|
|
135
|
+
if (op[0] & 5) throw op[1];
|
|
136
|
+
return {
|
|
137
|
+
value: op[0] ? op[1] : void 0,
|
|
138
|
+
done: true
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
var loadingArray = [];
|
|
143
|
+
var strategy = 'loaded-first';
|
|
144
|
+
var sharedFlag = strategy;
|
|
145
|
+
// eslint-disable-next-line max-lines-per-function
|
|
146
|
+
var prefetchPlugin = function() {
|
|
147
|
+
return {
|
|
148
|
+
name: 'data-prefetch-runtime-plugin',
|
|
149
|
+
initContainer: function initContainer(options) {
|
|
150
|
+
var remoteSnapshot = options.remoteSnapshot, remoteInfo = options.remoteInfo, id = options.id, origin = options.origin;
|
|
151
|
+
var snapshot = remoteSnapshot;
|
|
152
|
+
var name = remoteInfo.name;
|
|
153
|
+
var prefetchOptions = {
|
|
154
|
+
name: name,
|
|
155
|
+
remote: remoteInfo,
|
|
156
|
+
origin: origin,
|
|
157
|
+
remoteSnapshot: snapshot
|
|
158
|
+
};
|
|
159
|
+
var signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
160
|
+
if (!signal) {
|
|
161
|
+
return options;
|
|
162
|
+
}
|
|
163
|
+
if (sharedFlag !== strategy) {
|
|
164
|
+
throw new Error("[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'");
|
|
165
|
+
}
|
|
166
|
+
var instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
167
|
+
var prefetchUrl;
|
|
168
|
+
// @ts-expect-error
|
|
169
|
+
if (snapshot.prefetchEntry) {
|
|
170
|
+
// @ts-expect-error
|
|
171
|
+
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
172
|
+
}
|
|
173
|
+
var exist = loadingArray.find(function(loading) {
|
|
174
|
+
return loading.id === id;
|
|
175
|
+
});
|
|
176
|
+
if (exist) {
|
|
177
|
+
return options;
|
|
178
|
+
}
|
|
179
|
+
var promise = instance.loadEntry(prefetchUrl).then(/*#__PURE__*/ _async_to_generator(function() {
|
|
180
|
+
var projectExports;
|
|
181
|
+
return _ts_generator(this, function(_state) {
|
|
182
|
+
switch(_state.label){
|
|
183
|
+
case 0:
|
|
184
|
+
projectExports = instance.getProjectExports();
|
|
185
|
+
if (!_instanceof(projectExports, Promise)) return [
|
|
186
|
+
3,
|
|
187
|
+
2
|
|
188
|
+
];
|
|
189
|
+
return [
|
|
190
|
+
4,
|
|
191
|
+
projectExports
|
|
192
|
+
];
|
|
193
|
+
case 1:
|
|
194
|
+
_state.sent();
|
|
195
|
+
_state.label = 2;
|
|
196
|
+
case 2:
|
|
197
|
+
return [
|
|
198
|
+
2,
|
|
199
|
+
Promise.resolve().then(function() {
|
|
200
|
+
var exports = instance.getExposeExports(id);
|
|
201
|
+
index.logger.info("1. Start Prefetch initContainer: ".concat(id, " - ").concat(performance.now()));
|
|
202
|
+
var result = Object.keys(exports).map(function(k) {
|
|
203
|
+
var value = instance.prefetch({
|
|
204
|
+
id: id,
|
|
205
|
+
functionId: k
|
|
206
|
+
});
|
|
207
|
+
var functionId = k;
|
|
208
|
+
return {
|
|
209
|
+
value: value,
|
|
210
|
+
functionId: functionId
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
return result;
|
|
214
|
+
})
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}));
|
|
219
|
+
loadingArray.push({
|
|
220
|
+
id: id,
|
|
221
|
+
promise: promise
|
|
222
|
+
});
|
|
223
|
+
return options;
|
|
224
|
+
},
|
|
225
|
+
afterResolve: function afterResolve(options) {
|
|
226
|
+
var remoteSnapshot = options.remoteSnapshot, remoteInfo = options.remoteInfo, id = options.id, origin = options.origin;
|
|
227
|
+
var snapshot = remoteSnapshot;
|
|
228
|
+
var name = remoteInfo.name;
|
|
229
|
+
var prefetchOptions = {
|
|
230
|
+
name: name,
|
|
231
|
+
remote: remoteInfo,
|
|
232
|
+
origin: origin,
|
|
233
|
+
remoteSnapshot: snapshot
|
|
234
|
+
};
|
|
235
|
+
var signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
236
|
+
if (!signal) {
|
|
237
|
+
return options;
|
|
238
|
+
}
|
|
239
|
+
var inited = loadingArray.some(function(info) {
|
|
240
|
+
return info.id === id;
|
|
241
|
+
});
|
|
242
|
+
if (!inited) {
|
|
243
|
+
return options;
|
|
244
|
+
}
|
|
245
|
+
if (sharedFlag !== strategy) {
|
|
246
|
+
throw new Error("[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'");
|
|
247
|
+
}
|
|
248
|
+
var instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
249
|
+
var prefetchUrl;
|
|
250
|
+
// @ts-expect-error
|
|
251
|
+
if (snapshot.prefetchEntry) {
|
|
252
|
+
// @ts-expect-error
|
|
253
|
+
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
254
|
+
}
|
|
255
|
+
var index$1 = loadingArray.findIndex(function(loading) {
|
|
256
|
+
return loading.id === id;
|
|
257
|
+
});
|
|
258
|
+
// clear cache
|
|
259
|
+
if (index$1 !== -1) {
|
|
260
|
+
loadingArray.splice(index$1, 1);
|
|
261
|
+
}
|
|
262
|
+
var promise = instance.loadEntry(prefetchUrl).then(/*#__PURE__*/ _async_to_generator(function() {
|
|
263
|
+
var projectExports;
|
|
264
|
+
return _ts_generator(this, function(_state) {
|
|
265
|
+
switch(_state.label){
|
|
266
|
+
case 0:
|
|
267
|
+
projectExports = instance.getProjectExports();
|
|
268
|
+
if (!_instanceof(projectExports, Promise)) return [
|
|
269
|
+
3,
|
|
270
|
+
2
|
|
271
|
+
];
|
|
272
|
+
return [
|
|
273
|
+
4,
|
|
274
|
+
projectExports
|
|
275
|
+
];
|
|
276
|
+
case 1:
|
|
277
|
+
_state.sent();
|
|
278
|
+
_state.label = 2;
|
|
279
|
+
case 2:
|
|
280
|
+
return [
|
|
281
|
+
2,
|
|
282
|
+
Promise.resolve().then(function() {
|
|
283
|
+
var exports = instance.getExposeExports(id);
|
|
284
|
+
index.logger.info("1. Start Prefetch afterResolve: ".concat(id, " - ").concat(performance.now()));
|
|
285
|
+
var result = Object.keys(exports).map(function(k) {
|
|
286
|
+
var value = instance.prefetch({
|
|
287
|
+
id: id,
|
|
288
|
+
functionId: k
|
|
289
|
+
});
|
|
290
|
+
var functionId = k;
|
|
291
|
+
return {
|
|
292
|
+
value: value,
|
|
293
|
+
functionId: functionId
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
return result;
|
|
297
|
+
})
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}));
|
|
302
|
+
loadingArray.push({
|
|
303
|
+
id: id,
|
|
304
|
+
promise: promise
|
|
305
|
+
});
|
|
306
|
+
return options;
|
|
307
|
+
},
|
|
308
|
+
onLoad: function onLoad(options) {
|
|
309
|
+
return _async_to_generator(function() {
|
|
310
|
+
var _loadingArray_find, remote, id, name, promise, prefetch$1, prefetchValue, instance;
|
|
311
|
+
return _ts_generator(this, function(_state) {
|
|
312
|
+
switch(_state.label){
|
|
313
|
+
case 0:
|
|
314
|
+
remote = options.remote, id = options.id;
|
|
315
|
+
name = remote.name;
|
|
316
|
+
promise = (_loadingArray_find = loadingArray.find(function(loading) {
|
|
317
|
+
return loading.id === id;
|
|
318
|
+
})) === null || _loadingArray_find === void 0 ? void 0 : _loadingArray_find.promise;
|
|
319
|
+
if (!promise) return [
|
|
320
|
+
3,
|
|
321
|
+
3
|
|
322
|
+
];
|
|
323
|
+
return [
|
|
324
|
+
4,
|
|
325
|
+
promise
|
|
326
|
+
];
|
|
327
|
+
case 1:
|
|
328
|
+
prefetch$1 = _state.sent();
|
|
329
|
+
prefetchValue = prefetch$1.map(function(result) {
|
|
330
|
+
return result.value;
|
|
331
|
+
});
|
|
332
|
+
return [
|
|
333
|
+
4,
|
|
334
|
+
Promise.all(prefetchValue)
|
|
335
|
+
];
|
|
336
|
+
case 2:
|
|
337
|
+
_state.sent();
|
|
338
|
+
instance = prefetch.MFDataPrefetch.getInstance(name);
|
|
339
|
+
prefetch$1.forEach(function(result) {
|
|
340
|
+
var value = result.value, functionId = result.functionId;
|
|
341
|
+
instance.memorize(id + functionId, value);
|
|
342
|
+
});
|
|
343
|
+
_state.label = 3;
|
|
344
|
+
case 3:
|
|
345
|
+
return [
|
|
346
|
+
2,
|
|
347
|
+
options
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
})();
|
|
352
|
+
},
|
|
353
|
+
beforeLoadShare: function beforeLoadShare(options) {
|
|
354
|
+
var shareInfo = options.shareInfo;
|
|
355
|
+
sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
356
|
+
return options;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
exports["default"] = prefetchPlugin;
|
|
362
|
+
exports.prefetchPlugin = prefetchPlugin;
|