@module-federation/data-prefetch 0.6.7 → 0.6.9
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/.swcrc +29 -0
- package/CHANGELOG.md +18 -0
- package/dist/babel.cjs.js +23 -35
- package/dist/babel.esm.d.ts +2 -0
- package/dist/babel.esm.js +23 -31
- package/dist/cli.cjs.js +122 -3546
- package/dist/cli.esm.d.ts +1 -0
- package/dist/cli.esm.js +123 -3536
- package/dist/index.cjs.js +0 -2
- package/dist/index.esm.d.ts +1 -0
- package/dist/package.json +7 -6
- package/dist/plugin.cjs.js +95 -298
- package/dist/plugin.esm.d.ts +2 -0
- package/dist/plugin.esm.js +94 -297
- package/dist/polyfills.cjs.js +14 -0
- package/dist/polyfills.esm.js +12 -0
- package/dist/prefetch.cjs.js +118 -327
- package/dist/prefetch.esm.js +119 -328
- package/dist/react.cjs.js +31 -117
- package/dist/react.esm.d.ts +1 -0
- package/dist/react.esm.js +32 -116
- package/dist/runtime-utils.cjs.js +4 -8
- package/dist/runtime-utils.esm.js +5 -9
- package/dist/shared.cjs.js +10 -12
- package/dist/shared.esm.d.ts +2 -0
- package/dist/shared.esm.js +10 -12
- package/dist/universal.cjs.js +8 -17
- package/dist/universal.esm.d.ts +1 -0
- package/dist/universal.esm.js +9 -16
- package/package.json +5 -5
- package/project.json +2 -2
- package/rollup.config.js +22 -1
package/dist/prefetch.esm.js
CHANGED
|
@@ -1,349 +1,140 @@
|
|
|
1
1
|
import { getRemoteInfo, getRemoteEntry } from '@module-federation/runtime';
|
|
2
2
|
import { loadScript } from '@module-federation/sdk';
|
|
3
|
-
import {
|
|
3
|
+
import { b as getPrefetchId, c as compatGetPrefetchId } from './runtime-utils.esm.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
var // @ts-ignore init global variable for test
|
|
6
|
+
_globalThis, _globalThis___FEDERATION__;
|
|
7
|
+
var ___FEDERATION__;
|
|
8
|
+
(___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) != null ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
|
|
9
|
+
var ___PREFETCH__;
|
|
10
|
+
(___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) != null ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
|
|
11
|
+
entryLoading: {},
|
|
12
|
+
instance: new Map(),
|
|
13
|
+
__PREFETCH_EXPORTS__: {}
|
|
14
|
+
};
|
|
15
|
+
class MFDataPrefetch {
|
|
16
|
+
get global() {
|
|
17
|
+
return globalThis.__FEDERATION__.__PREFETCH__;
|
|
12
18
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} else {
|
|
16
|
-
Promise.resolve(value).then(_next, _throw);
|
|
19
|
+
static getInstance(id) {
|
|
20
|
+
return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
26
|
-
}
|
|
27
|
-
function _throw(err) {
|
|
28
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
22
|
+
async loadEntry(entry) {
|
|
23
|
+
const { name, remoteSnapshot, remote, origin } = this._options;
|
|
24
|
+
if (entry) {
|
|
25
|
+
const { buildVersion, globalName } = remoteSnapshot;
|
|
26
|
+
const uniqueKey = globalName || `${name}:${buildVersion}`;
|
|
27
|
+
if (!this.global.entryLoading[uniqueKey]) {
|
|
28
|
+
this.global.entryLoading[uniqueKey] = loadScript(entry, {});
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for(var i = 0; i < props.length; i++){
|
|
41
|
-
var descriptor = props[i];
|
|
42
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
43
|
-
descriptor.configurable = true;
|
|
44
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
45
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
30
|
+
return this.global.entryLoading[uniqueKey];
|
|
31
|
+
} else {
|
|
32
|
+
const remoteInfo = getRemoteInfo(remote);
|
|
33
|
+
const module = origin.moduleCache.get(remoteInfo.name);
|
|
34
|
+
return getRemoteEntry({
|
|
35
|
+
origin: origin,
|
|
36
|
+
remoteInfo,
|
|
37
|
+
remoteEntryExports: module ? module.remoteEntryExports : undefined
|
|
38
|
+
});
|
|
39
|
+
}
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
getProjectExports() {
|
|
42
|
+
var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
|
|
43
|
+
if (Object.keys(this._exports).length > 0) {
|
|
44
|
+
return this._exports;
|
|
45
|
+
}
|
|
46
|
+
const { name } = this._options;
|
|
47
|
+
const exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
|
|
48
|
+
const exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
|
|
49
|
+
const resolve = exportsPromise.then((exports = {})=>{
|
|
50
|
+
// Match prefetch based on the function name suffix so that other capabilities can be expanded later.
|
|
51
|
+
// Not all functions should be directly identified as prefetch functions
|
|
52
|
+
const memory = {};
|
|
53
|
+
Object.keys(exports).forEach((key)=>{
|
|
54
|
+
memory[key] = {};
|
|
55
|
+
const exportVal = exports[key];
|
|
56
|
+
Object.keys(exportVal).reduce((memo, current)=>{
|
|
57
|
+
if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
|
|
58
|
+
memo[current] = exportVal[current];
|
|
59
|
+
}
|
|
60
|
+
return memo;
|
|
61
|
+
}, memory[key]);
|
|
62
|
+
});
|
|
63
|
+
this.memorizeExports(memory);
|
|
60
64
|
});
|
|
61
|
-
|
|
62
|
-
obj[key] = value;
|
|
65
|
+
return resolve;
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function _ts_generator(thisArg, body) {
|
|
67
|
-
var f, y, t, g, _ = {
|
|
68
|
-
label: 0,
|
|
69
|
-
sent: function() {
|
|
70
|
-
if (t[0] & 1) throw t[1];
|
|
71
|
-
return t[1];
|
|
72
|
-
},
|
|
73
|
-
trys: [],
|
|
74
|
-
ops: []
|
|
75
|
-
};
|
|
76
|
-
return g = {
|
|
77
|
-
next: verb(0),
|
|
78
|
-
"throw": verb(1),
|
|
79
|
-
"return": verb(2)
|
|
80
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
81
|
-
return this;
|
|
82
|
-
}), g;
|
|
83
|
-
function verb(n) {
|
|
84
|
-
return function(v) {
|
|
85
|
-
return step([
|
|
86
|
-
n,
|
|
87
|
-
v
|
|
88
|
-
]);
|
|
89
|
-
};
|
|
67
|
+
memorizeExports(exports) {
|
|
68
|
+
this._exports = exports;
|
|
90
69
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case 7:
|
|
118
|
-
op = _.ops.pop();
|
|
119
|
-
_.trys.pop();
|
|
120
|
-
continue;
|
|
121
|
-
default:
|
|
122
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
123
|
-
_ = 0;
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
127
|
-
_.label = op[1];
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
131
|
-
_.label = t[1];
|
|
132
|
-
t = op;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
if (t && _.label < t[2]) {
|
|
136
|
-
_.label = t[2];
|
|
137
|
-
_.ops.push(op);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
if (t[2]) _.ops.pop();
|
|
141
|
-
_.trys.pop();
|
|
142
|
-
continue;
|
|
70
|
+
getExposeExports(id) {
|
|
71
|
+
const prefetchId = getPrefetchId(id);
|
|
72
|
+
const compatId = compatGetPrefetchId(id);
|
|
73
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
74
|
+
return prefetchExports || {};
|
|
75
|
+
}
|
|
76
|
+
prefetch(prefetchOptions) {
|
|
77
|
+
const { id, functionId = 'default', refetchParams } = prefetchOptions;
|
|
78
|
+
let prefetchResult;
|
|
79
|
+
const prefetchId = getPrefetchId(id);
|
|
80
|
+
const compatId = compatGetPrefetchId(id);
|
|
81
|
+
const memorizeId = id + functionId;
|
|
82
|
+
const memory = this.prefetchMemory.get(memorizeId);
|
|
83
|
+
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
84
|
+
return memory;
|
|
85
|
+
}
|
|
86
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
87
|
+
if (!prefetchExports) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const executePrefetch = prefetchExports[functionId];
|
|
91
|
+
if (typeof executePrefetch === 'function') {
|
|
92
|
+
if (refetchParams) {
|
|
93
|
+
prefetchResult = executePrefetch(refetchParams);
|
|
94
|
+
} else {
|
|
95
|
+
prefetchResult = executePrefetch();
|
|
143
96
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
op = [
|
|
147
|
-
6,
|
|
148
|
-
e
|
|
149
|
-
];
|
|
150
|
-
y = 0;
|
|
151
|
-
} finally{
|
|
152
|
-
f = t = 0;
|
|
97
|
+
} else {
|
|
98
|
+
throw new Error(`[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`);
|
|
153
99
|
}
|
|
154
|
-
|
|
155
|
-
return
|
|
156
|
-
value: op[0] ? op[1] : void 0,
|
|
157
|
-
done: true
|
|
158
|
-
};
|
|
100
|
+
this.memorize(memorizeId, prefetchResult);
|
|
101
|
+
return prefetchResult;
|
|
159
102
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
103
|
+
memorize(id, value) {
|
|
104
|
+
this.prefetchMemory.set(id, value);
|
|
105
|
+
}
|
|
106
|
+
markOutdate(markOptions, isOutdate) {
|
|
107
|
+
const { id, functionId = 'default' } = markOptions;
|
|
108
|
+
if (!this.recordOutdate[id]) {
|
|
109
|
+
this.recordOutdate[id] = {};
|
|
110
|
+
}
|
|
111
|
+
this.recordOutdate[id][functionId] = isOutdate;
|
|
112
|
+
}
|
|
113
|
+
checkOutdate(outdateOptions) {
|
|
114
|
+
const { id, functionId = 'default', cacheStrategy } = outdateOptions;
|
|
115
|
+
if (typeof cacheStrategy === 'function') {
|
|
116
|
+
return cacheStrategy();
|
|
117
|
+
}
|
|
118
|
+
if (!this.recordOutdate[id]) {
|
|
119
|
+
this.recordOutdate[id] = {};
|
|
120
|
+
}
|
|
121
|
+
if (this.recordOutdate[id][functionId]) {
|
|
122
|
+
this.markOutdate({
|
|
123
|
+
id,
|
|
124
|
+
functionId
|
|
125
|
+
}, false);
|
|
126
|
+
return true;
|
|
127
|
+
} else {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
constructor(options){
|
|
178
132
|
this.prefetchMemory = new Map();
|
|
179
133
|
this.recordOutdate = {};
|
|
180
134
|
this._exports = {};
|
|
181
135
|
this._options = options;
|
|
182
136
|
this.global.instance.set(options.name, this);
|
|
183
137
|
}
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
key: "global",
|
|
187
|
-
get: function get() {
|
|
188
|
-
return globalThis.__FEDERATION__.__PREFETCH__;
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
key: "loadEntry",
|
|
193
|
-
value: function loadEntry(entry) {
|
|
194
|
-
var _this = this;
|
|
195
|
-
return _async_to_generator(function() {
|
|
196
|
-
var _this__options, name, remoteSnapshot, remote, origin, buildVersion, globalName, uniqueKey, remoteInfo, module;
|
|
197
|
-
return _ts_generator(this, function(_state) {
|
|
198
|
-
_this__options = _this._options, name = _this__options.name, remoteSnapshot = _this__options.remoteSnapshot, remote = _this__options.remote, origin = _this__options.origin;
|
|
199
|
-
if (entry) {
|
|
200
|
-
buildVersion = remoteSnapshot.buildVersion, globalName = remoteSnapshot.globalName;
|
|
201
|
-
uniqueKey = globalName || "".concat(name, ":").concat(buildVersion);
|
|
202
|
-
if (!_this.global.entryLoading[uniqueKey]) {
|
|
203
|
-
_this.global.entryLoading[uniqueKey] = loadScript(entry, {});
|
|
204
|
-
}
|
|
205
|
-
return [
|
|
206
|
-
2,
|
|
207
|
-
_this.global.entryLoading[uniqueKey]
|
|
208
|
-
];
|
|
209
|
-
} else {
|
|
210
|
-
remoteInfo = getRemoteInfo(remote);
|
|
211
|
-
module = origin.moduleCache.get(remoteInfo.name);
|
|
212
|
-
return [
|
|
213
|
-
2,
|
|
214
|
-
getRemoteEntry({
|
|
215
|
-
origin: origin,
|
|
216
|
-
remoteInfo: remoteInfo,
|
|
217
|
-
remoteEntryExports: module ? module.remoteEntryExports : undefined
|
|
218
|
-
})
|
|
219
|
-
];
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
})();
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
key: "getProjectExports",
|
|
227
|
-
value: function getProjectExports() {
|
|
228
|
-
var _this = this;
|
|
229
|
-
var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
|
|
230
|
-
if (Object.keys(this._exports).length > 0) {
|
|
231
|
-
return this._exports;
|
|
232
|
-
}
|
|
233
|
-
var name = this._options.name;
|
|
234
|
-
var exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) === null || _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ === void 0 ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
|
|
235
|
-
var exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
|
|
236
|
-
var resolve = exportsPromise.then(function() {
|
|
237
|
-
var exports = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
238
|
-
// Match prefetch based on the function name suffix so that other capabilities can be expanded later.
|
|
239
|
-
// Not all functions should be directly identified as prefetch functions
|
|
240
|
-
var memory = {};
|
|
241
|
-
Object.keys(exports).forEach(function(key) {
|
|
242
|
-
memory[key] = {};
|
|
243
|
-
var exportVal = exports[key];
|
|
244
|
-
Object.keys(exportVal).reduce(function(memo, current) {
|
|
245
|
-
if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
|
|
246
|
-
memo[current] = exportVal[current];
|
|
247
|
-
}
|
|
248
|
-
return memo;
|
|
249
|
-
}, memory[key]);
|
|
250
|
-
});
|
|
251
|
-
_this.memorizeExports(memory);
|
|
252
|
-
});
|
|
253
|
-
return resolve;
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
key: "memorizeExports",
|
|
258
|
-
value: function memorizeExports(exports) {
|
|
259
|
-
this._exports = exports;
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
key: "getExposeExports",
|
|
264
|
-
value: function getExposeExports(id) {
|
|
265
|
-
var prefetchId = getPrefetchId(id);
|
|
266
|
-
var compatId = compatGetPrefetchId(id);
|
|
267
|
-
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
268
|
-
return prefetchExports || {};
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
key: "prefetch",
|
|
273
|
-
value: function prefetch(prefetchOptions) {
|
|
274
|
-
var id = prefetchOptions.id, _prefetchOptions_functionId = prefetchOptions.functionId, functionId = _prefetchOptions_functionId === void 0 ? 'default' : _prefetchOptions_functionId, refetchParams = prefetchOptions.refetchParams;
|
|
275
|
-
var prefetchResult;
|
|
276
|
-
var prefetchId = getPrefetchId(id);
|
|
277
|
-
var compatId = compatGetPrefetchId(id);
|
|
278
|
-
var memorizeId = id + functionId;
|
|
279
|
-
var memory = this.prefetchMemory.get(memorizeId);
|
|
280
|
-
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
281
|
-
return memory;
|
|
282
|
-
}
|
|
283
|
-
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
284
|
-
if (!prefetchExports) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
var executePrefetch = prefetchExports[functionId];
|
|
288
|
-
if (typeof executePrefetch === 'function') {
|
|
289
|
-
if (refetchParams) {
|
|
290
|
-
prefetchResult = executePrefetch(refetchParams);
|
|
291
|
-
} else {
|
|
292
|
-
prefetchResult = executePrefetch();
|
|
293
|
-
}
|
|
294
|
-
} else {
|
|
295
|
-
throw new Error("[Module Federation Data Prefetch]: No prefetch function called ".concat(functionId, " export in prefetch file"));
|
|
296
|
-
}
|
|
297
|
-
this.memorize(memorizeId, prefetchResult);
|
|
298
|
-
return prefetchResult;
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
key: "memorize",
|
|
303
|
-
value: function memorize(id, value) {
|
|
304
|
-
this.prefetchMemory.set(id, value);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
key: "markOutdate",
|
|
309
|
-
value: function markOutdate(markOptions, isOutdate) {
|
|
310
|
-
var id = markOptions.id, _markOptions_functionId = markOptions.functionId, functionId = _markOptions_functionId === void 0 ? 'default' : _markOptions_functionId;
|
|
311
|
-
if (!this.recordOutdate[id]) {
|
|
312
|
-
this.recordOutdate[id] = {};
|
|
313
|
-
}
|
|
314
|
-
this.recordOutdate[id][functionId] = isOutdate;
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
key: "checkOutdate",
|
|
319
|
-
value: function checkOutdate(outdateOptions) {
|
|
320
|
-
var id = outdateOptions.id, _outdateOptions_functionId = outdateOptions.functionId, functionId = _outdateOptions_functionId === void 0 ? 'default' : _outdateOptions_functionId, cacheStrategy = outdateOptions.cacheStrategy;
|
|
321
|
-
if (typeof cacheStrategy === 'function') {
|
|
322
|
-
return cacheStrategy();
|
|
323
|
-
}
|
|
324
|
-
if (!this.recordOutdate[id]) {
|
|
325
|
-
this.recordOutdate[id] = {};
|
|
326
|
-
}
|
|
327
|
-
if (this.recordOutdate[id][functionId]) {
|
|
328
|
-
this.markOutdate({
|
|
329
|
-
id: id,
|
|
330
|
-
functionId: functionId
|
|
331
|
-
}, false);
|
|
332
|
-
return true;
|
|
333
|
-
} else {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
], [
|
|
339
|
-
{
|
|
340
|
-
key: "getInstance",
|
|
341
|
-
value: function getInstance(id) {
|
|
342
|
-
return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
]);
|
|
346
|
-
return MFDataPrefetch;
|
|
347
|
-
}();
|
|
138
|
+
}
|
|
348
139
|
|
|
349
140
|
export { MFDataPrefetch as M };
|
package/dist/react.cjs.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var polyfills = require('./polyfills.cjs.js');
|
|
5
4
|
var react = require('react');
|
|
6
5
|
var index = require('./index.cjs2.js');
|
|
7
6
|
var prefetch = require('./prefetch.cjs.js');
|
|
@@ -10,142 +9,57 @@ var runtimeUtils = require('./runtime-utils.cjs.js');
|
|
|
10
9
|
require('@module-federation/sdk');
|
|
11
10
|
require('@module-federation/runtime');
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
react.useEffect(
|
|
12
|
+
const useFirstMounted = ()=>{
|
|
13
|
+
const ref = react.useRef(true);
|
|
14
|
+
react.useEffect(()=>{
|
|
16
15
|
ref.current = false;
|
|
17
16
|
}, []);
|
|
18
17
|
return ref.current;
|
|
19
18
|
};
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
24
|
-
return arr2;
|
|
25
|
-
}
|
|
26
|
-
function _array_with_holes(arr) {
|
|
27
|
-
if (Array.isArray(arr)) return arr;
|
|
28
|
-
}
|
|
29
|
-
function _define_property(obj, key, value) {
|
|
30
|
-
if (key in obj) {
|
|
31
|
-
Object.defineProperty(obj, key, {
|
|
32
|
-
value: value,
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
obj[key] = value;
|
|
39
|
-
}
|
|
40
|
-
return obj;
|
|
41
|
-
}
|
|
42
|
-
function _instanceof(left, right) {
|
|
43
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
44
|
-
return !!right[Symbol.hasInstance](left);
|
|
45
|
-
} else {
|
|
46
|
-
return left instanceof right;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function _iterable_to_array_limit(arr, i) {
|
|
50
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
51
|
-
if (_i == null) return;
|
|
52
|
-
var _arr = [];
|
|
53
|
-
var _n = true;
|
|
54
|
-
var _d = false;
|
|
55
|
-
var _s, _e;
|
|
56
|
-
try {
|
|
57
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
58
|
-
_arr.push(_s.value);
|
|
59
|
-
if (i && _arr.length === i) break;
|
|
60
|
-
}
|
|
61
|
-
} catch (err) {
|
|
62
|
-
_d = true;
|
|
63
|
-
_e = err;
|
|
64
|
-
} finally{
|
|
65
|
-
try {
|
|
66
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
67
|
-
} finally{
|
|
68
|
-
if (_d) throw _e;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return _arr;
|
|
72
|
-
}
|
|
73
|
-
function _non_iterable_rest() {
|
|
74
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
75
|
-
}
|
|
76
|
-
function _object_spread(target) {
|
|
77
|
-
for(var i = 1; i < arguments.length; i++){
|
|
78
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
79
|
-
var ownKeys = Object.keys(source);
|
|
80
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
81
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
82
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
ownKeys.forEach(function(key) {
|
|
86
|
-
_define_property(target, key, source[key]);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return target;
|
|
90
|
-
}
|
|
91
|
-
function _sliced_to_array(arr, i) {
|
|
92
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
93
|
-
}
|
|
94
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
95
|
-
if (!o) return;
|
|
96
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
97
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
98
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
99
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
100
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
101
|
-
}
|
|
102
|
-
var usePrefetch = function(options) {
|
|
103
|
-
var isFirstMounted = useFirstMounted();
|
|
20
|
+
const usePrefetch = (options)=>{
|
|
21
|
+
const isFirstMounted = useFirstMounted();
|
|
104
22
|
if (isFirstMounted) {
|
|
105
|
-
|
|
106
|
-
index.logger.info(
|
|
23
|
+
const startTiming = performance.now();
|
|
24
|
+
index.logger.info(`2. Start Get Prefetch Data: ${options.id} - ${options.functionId || 'default'} - ${startTiming}`);
|
|
107
25
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
id
|
|
111
|
-
functionId
|
|
26
|
+
const { id, functionId, deferId } = options;
|
|
27
|
+
const prefetchInfo = {
|
|
28
|
+
id,
|
|
29
|
+
functionId
|
|
112
30
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
31
|
+
const mfScope = runtimeUtils.getScope();
|
|
32
|
+
let state;
|
|
33
|
+
const prefetchResult = universal.prefetch(options);
|
|
116
34
|
if (deferId) {
|
|
117
|
-
if (
|
|
118
|
-
state = prefetchResult.then(
|
|
119
|
-
return deferredData.data[deferId];
|
|
120
|
-
});
|
|
35
|
+
if (prefetchResult instanceof Promise) {
|
|
36
|
+
state = prefetchResult.then((deferredData)=>deferredData.data[deferId]);
|
|
121
37
|
} else {
|
|
122
38
|
state = prefetchResult.data[deferId];
|
|
123
39
|
}
|
|
124
40
|
} else {
|
|
125
41
|
state = prefetchResult;
|
|
126
42
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
react.useEffect(
|
|
130
|
-
|
|
131
|
-
index.logger.info(
|
|
132
|
-
return
|
|
133
|
-
prefetchInstance
|
|
43
|
+
const [prefetchState, setPrefetchState] = react.useState(state);
|
|
44
|
+
const prefetchInstance = prefetch.MFDataPrefetch.getInstance(mfScope);
|
|
45
|
+
react.useEffect(()=>{
|
|
46
|
+
const useEffectTiming = performance.now();
|
|
47
|
+
index.logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
|
|
48
|
+
return ()=>{
|
|
49
|
+
prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
|
|
134
50
|
};
|
|
135
51
|
}, []);
|
|
136
|
-
|
|
137
|
-
|
|
52
|
+
const refreshExecutor = (refetchParams)=>{
|
|
53
|
+
const refetchOptions = polyfills._extends({}, options);
|
|
138
54
|
if (refetchParams) {
|
|
139
55
|
refetchOptions.refetchParams = refetchParams;
|
|
140
56
|
}
|
|
141
|
-
prefetchInstance
|
|
142
|
-
|
|
143
|
-
|
|
57
|
+
prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
|
|
58
|
+
const newVal = universal.prefetch(refetchOptions);
|
|
59
|
+
let newState;
|
|
144
60
|
if (deferId) {
|
|
145
|
-
if (
|
|
146
|
-
newState = newVal.then(
|
|
147
|
-
return deferredData.data[deferId];
|
|
148
|
-
});
|
|
61
|
+
if (newVal instanceof Promise) {
|
|
62
|
+
newState = newVal.then((deferredData)=>deferredData.data[deferId]);
|
|
149
63
|
} else {
|
|
150
64
|
newState = newVal.data[deferId];
|
|
151
65
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/react/index";
|