@alicloud/alfa-react 2.0.1 → 2.0.3-alpha.0
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/es/createAlfaWidget.js +66 -44
- package/es/createApplication.js +11 -6
- package/es/version.js +1 -1
- package/lib/createAlfaWidget.js +66 -44
- package/lib/createApplication.js +11 -6
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/types/types/index.d.ts +4 -0
- package/types/version.d.ts +1 -1
package/es/createAlfaWidget.js
CHANGED
|
@@ -44,7 +44,8 @@ function createAlfaWidget(option) {
|
|
|
44
44
|
var _ref2 = option || {},
|
|
45
45
|
name = _ref2.name,
|
|
46
46
|
dependencies = _ref2.dependencies,
|
|
47
|
-
priority = _ref2.priority,
|
|
47
|
+
_ref2$priority = _ref2.priority,
|
|
48
|
+
priority = _ref2$priority === void 0 ? 'medium' : _ref2$priority,
|
|
48
49
|
dynamicConfig = _ref2.dynamicConfig,
|
|
49
50
|
manifest = _ref2.manifest,
|
|
50
51
|
loading = _ref2.loading,
|
|
@@ -60,51 +61,69 @@ function createAlfaWidget(option) {
|
|
|
60
61
|
if (!name) return function () {
|
|
61
62
|
return null;
|
|
62
63
|
};
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
container: document.body,
|
|
68
|
-
dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
|
|
69
|
-
}));
|
|
70
|
-
preLoader = /*#__PURE__*/function () {
|
|
71
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
72
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
73
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
74
|
-
case 0:
|
|
75
|
-
return _context2.abrupt("return", p);
|
|
76
|
-
case 1:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context2.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee2);
|
|
81
|
-
}));
|
|
82
|
-
return function preLoader() {
|
|
83
|
-
return _ref3.apply(this, arguments);
|
|
84
|
-
};
|
|
85
|
-
}();
|
|
86
|
-
}
|
|
64
|
+
var register;
|
|
65
|
+
// createAlfaWidget 创建的组件是否已经初始化
|
|
66
|
+
// 通过该变量判断是否还需要预加载
|
|
67
|
+
var initialized = false;
|
|
87
68
|
var passedInOption = _objectSpread(_objectSpread({}, option), {}, {
|
|
69
|
+
noCache: true,
|
|
88
70
|
sandbox: _objectSpread(_objectSpread({}, sandbox), {}, {
|
|
89
71
|
sandBoxUrl: 'about:blank'
|
|
90
|
-
})
|
|
72
|
+
}),
|
|
73
|
+
// 必须设置 container,否则沙箱会创建插入一个新的 body
|
|
74
|
+
container: document.body,
|
|
75
|
+
dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
|
|
91
76
|
});
|
|
77
|
+
var createRegister = function createRegister() {
|
|
78
|
+
var p = loader.register(passedInOption);
|
|
79
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
80
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
81
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
return _context2.abrupt("return", p);
|
|
84
|
+
case 1:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context2.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee2);
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// 创建延时函数
|
|
93
|
+
var createDelayPromise = function createDelayPromise() {
|
|
94
|
+
if (typeof delay === 'number') {
|
|
95
|
+
return new Promise(function (resolve) {
|
|
96
|
+
setTimeout(function () {
|
|
97
|
+
resolve();
|
|
98
|
+
}, delay);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (typeof delay === 'function') {
|
|
102
|
+
var fnReturn = delay();
|
|
103
|
+
if (typeof fnReturn.then === 'function') return fnReturn;
|
|
104
|
+
if (typeof fnReturn === 'number') return fnReturn;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
};
|
|
108
|
+
if (priority === 'high' && !IS_SSR) {
|
|
109
|
+
register = createRegister();
|
|
110
|
+
}
|
|
111
|
+
if (priority === 'medium' && !IS_SSR) {
|
|
112
|
+
// 默认优先级下,空闲时会去预加载微应用,而不是等待加载完成
|
|
113
|
+
if (typeof requestIdleCallback === 'function') {
|
|
114
|
+
requestIdleCallback(function () {
|
|
115
|
+
if (register || initialized) return;
|
|
116
|
+
register = createRegister();
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
setTimeout(function () {
|
|
120
|
+
if (register || initialized) return;
|
|
121
|
+
register = createRegister();
|
|
122
|
+
}, 0);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
92
125
|
var useDelay = function useDelay() {
|
|
93
|
-
return useMemo(
|
|
94
|
-
if (typeof delay === 'number') {
|
|
95
|
-
return new Promise(function (resolve) {
|
|
96
|
-
setTimeout(function () {
|
|
97
|
-
resolve();
|
|
98
|
-
}, delay);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (typeof delay === 'function') {
|
|
102
|
-
var fnReturn = delay();
|
|
103
|
-
if (typeof fnReturn.then === 'function') return fnReturn;
|
|
104
|
-
if (typeof fnReturn === 'number') return fnReturn;
|
|
105
|
-
}
|
|
106
|
-
return undefined;
|
|
107
|
-
}, []);
|
|
126
|
+
return useMemo(createDelayPromise, []);
|
|
108
127
|
};
|
|
109
128
|
if (priority === 'low' && !IS_SSR) {
|
|
110
129
|
return function (props) {
|
|
@@ -120,13 +139,16 @@ function createAlfaWidget(option) {
|
|
|
120
139
|
delayPromise: delayPromise,
|
|
121
140
|
style: props.style || passedInOption.style,
|
|
122
141
|
deps: dependencies || {},
|
|
123
|
-
customProps: _objectSpread({}, props)
|
|
124
|
-
|
|
142
|
+
customProps: _objectSpread({}, props)
|
|
143
|
+
// 低优先级下,不预加载
|
|
144
|
+
,
|
|
145
|
+
preLoader: undefined
|
|
125
146
|
}))));
|
|
126
147
|
};
|
|
127
148
|
}
|
|
128
149
|
return function (props) {
|
|
129
150
|
var delayPromise = useDelay();
|
|
151
|
+
initialized = true;
|
|
130
152
|
|
|
131
153
|
// Compatible with old logic
|
|
132
154
|
// props should not passed in errorBoundary
|
|
@@ -135,7 +157,7 @@ function createAlfaWidget(option) {
|
|
|
135
157
|
style: props.style || passedInOption.style,
|
|
136
158
|
deps: dependencies || {},
|
|
137
159
|
customProps: _objectSpread({}, props),
|
|
138
|
-
preLoader:
|
|
160
|
+
preLoader: register
|
|
139
161
|
})));
|
|
140
162
|
};
|
|
141
163
|
}
|
package/es/createApplication.js
CHANGED
|
@@ -58,6 +58,7 @@ export default function createApplication(loader) {
|
|
|
58
58
|
basename = props.basename,
|
|
59
59
|
channel = props.channel,
|
|
60
60
|
delayPromise = props.delayPromise,
|
|
61
|
+
forceLog = props.forceLog,
|
|
61
62
|
preLoader = props.preLoader;
|
|
62
63
|
var handleExternalLink = customProps.handleExternalLink;
|
|
63
64
|
var _useState = useState(null),
|
|
@@ -83,6 +84,7 @@ export default function createApplication(loader) {
|
|
|
83
84
|
preLoader: preLoader,
|
|
84
85
|
container: container
|
|
85
86
|
});
|
|
87
|
+
console.log('createApplication');
|
|
86
88
|
var onSyncHistory = useCallbackRef(props.onSyncHistory || function () {});
|
|
87
89
|
$syncHistory.current = syncHistory;
|
|
88
90
|
$basename.current = basename;
|
|
@@ -279,7 +281,8 @@ export default function createApplication(loader) {
|
|
|
279
281
|
}
|
|
280
282
|
return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
|
|
281
283
|
E_CODE: 'RuntimeError',
|
|
282
|
-
E_MSG: 'load app failed.'
|
|
284
|
+
E_MSG: 'load app failed.',
|
|
285
|
+
__force_log__: forceLog
|
|
283
286
|
}));
|
|
284
287
|
case 24:
|
|
285
288
|
if (appRef.current) {
|
|
@@ -288,7 +291,8 @@ export default function createApplication(loader) {
|
|
|
288
291
|
}
|
|
289
292
|
return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
|
|
290
293
|
E_CODE: 'RuntimeError',
|
|
291
|
-
E_MSG: 'cannot find container.'
|
|
294
|
+
E_MSG: 'cannot find container.',
|
|
295
|
+
__force_log__: forceLog
|
|
292
296
|
}));
|
|
293
297
|
case 26:
|
|
294
298
|
// update body in sandbox context
|
|
@@ -327,12 +331,13 @@ export default function createApplication(loader) {
|
|
|
327
331
|
window.history.go(n);
|
|
328
332
|
});
|
|
329
333
|
}
|
|
330
|
-
(logger === null || logger === void 0 ? void 0 : logger.record) &&
|
|
334
|
+
(logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
|
|
331
335
|
REQUEST_VERSION: memoOptions.version,
|
|
332
336
|
RESPONSE_VERSION: realVersion,
|
|
333
|
-
END_TIME: Date.now()
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
END_TIME: Date.now(),
|
|
338
|
+
__force_log__: forceLog
|
|
339
|
+
});
|
|
340
|
+
(logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
|
|
336
341
|
|
|
337
342
|
// just run once
|
|
338
343
|
setAppInstance(app);
|
package/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '2.0.
|
|
1
|
+
export var version = '2.0.3-alpha.0';
|
package/lib/createAlfaWidget.js
CHANGED
|
@@ -56,7 +56,8 @@ function createAlfaWidget(option) {
|
|
|
56
56
|
var _ref2 = option || {},
|
|
57
57
|
name = _ref2.name,
|
|
58
58
|
dependencies = _ref2.dependencies,
|
|
59
|
-
priority = _ref2.priority,
|
|
59
|
+
_ref2$priority = _ref2.priority,
|
|
60
|
+
priority = _ref2$priority === void 0 ? 'medium' : _ref2$priority,
|
|
60
61
|
dynamicConfig = _ref2.dynamicConfig,
|
|
61
62
|
manifest = _ref2.manifest,
|
|
62
63
|
loading = _ref2.loading,
|
|
@@ -72,51 +73,69 @@ function createAlfaWidget(option) {
|
|
|
72
73
|
if (!name) return function () {
|
|
73
74
|
return null;
|
|
74
75
|
};
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
container: document.body,
|
|
80
|
-
dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
|
|
81
|
-
}));
|
|
82
|
-
preLoader = /*#__PURE__*/function () {
|
|
83
|
-
var _ref3 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
84
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
85
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
86
|
-
case 0:
|
|
87
|
-
return _context2.abrupt("return", p);
|
|
88
|
-
case 1:
|
|
89
|
-
case "end":
|
|
90
|
-
return _context2.stop();
|
|
91
|
-
}
|
|
92
|
-
}, _callee2);
|
|
93
|
-
}));
|
|
94
|
-
return function preLoader() {
|
|
95
|
-
return _ref3.apply(this, arguments);
|
|
96
|
-
};
|
|
97
|
-
}();
|
|
98
|
-
}
|
|
76
|
+
var register;
|
|
77
|
+
// createAlfaWidget 创建的组件是否已经初始化
|
|
78
|
+
// 通过该变量判断是否还需要预加载
|
|
79
|
+
var initialized = false;
|
|
99
80
|
var passedInOption = _objectSpread(_objectSpread({}, option), {}, {
|
|
81
|
+
noCache: true,
|
|
100
82
|
sandbox: _objectSpread(_objectSpread({}, sandbox), {}, {
|
|
101
83
|
sandBoxUrl: 'about:blank'
|
|
102
|
-
})
|
|
84
|
+
}),
|
|
85
|
+
// 必须设置 container,否则沙箱会创建插入一个新的 body
|
|
86
|
+
container: document.body,
|
|
87
|
+
dynamicConfig: typeof dynamicConfig === 'boolean' ? dynamicConfig : !manifest
|
|
103
88
|
});
|
|
89
|
+
var createRegister = function createRegister() {
|
|
90
|
+
var p = loader.register(passedInOption);
|
|
91
|
+
return /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
92
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
93
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
94
|
+
case 0:
|
|
95
|
+
return _context2.abrupt("return", p);
|
|
96
|
+
case 1:
|
|
97
|
+
case "end":
|
|
98
|
+
return _context2.stop();
|
|
99
|
+
}
|
|
100
|
+
}, _callee2);
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// 创建延时函数
|
|
105
|
+
var createDelayPromise = function createDelayPromise() {
|
|
106
|
+
if (typeof delay === 'number') {
|
|
107
|
+
return new Promise(function (resolve) {
|
|
108
|
+
setTimeout(function () {
|
|
109
|
+
resolve();
|
|
110
|
+
}, delay);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (typeof delay === 'function') {
|
|
114
|
+
var fnReturn = delay();
|
|
115
|
+
if (typeof fnReturn.then === 'function') return fnReturn;
|
|
116
|
+
if (typeof fnReturn === 'number') return fnReturn;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
};
|
|
120
|
+
if (priority === 'high' && !_utils.IS_SSR) {
|
|
121
|
+
register = createRegister();
|
|
122
|
+
}
|
|
123
|
+
if (priority === 'medium' && !_utils.IS_SSR) {
|
|
124
|
+
// 默认优先级下,空闲时会去预加载微应用,而不是等待加载完成
|
|
125
|
+
if (typeof requestIdleCallback === 'function') {
|
|
126
|
+
requestIdleCallback(function () {
|
|
127
|
+
if (register || initialized) return;
|
|
128
|
+
register = createRegister();
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
setTimeout(function () {
|
|
132
|
+
if (register || initialized) return;
|
|
133
|
+
register = createRegister();
|
|
134
|
+
}, 0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
104
137
|
var useDelay = function useDelay() {
|
|
105
|
-
return (0, _react.useMemo)(
|
|
106
|
-
if (typeof delay === 'number') {
|
|
107
|
-
return new Promise(function (resolve) {
|
|
108
|
-
setTimeout(function () {
|
|
109
|
-
resolve();
|
|
110
|
-
}, delay);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (typeof delay === 'function') {
|
|
114
|
-
var fnReturn = delay();
|
|
115
|
-
if (typeof fnReturn.then === 'function') return fnReturn;
|
|
116
|
-
if (typeof fnReturn === 'number') return fnReturn;
|
|
117
|
-
}
|
|
118
|
-
return undefined;
|
|
119
|
-
}, []);
|
|
138
|
+
return (0, _react.useMemo)(createDelayPromise, []);
|
|
120
139
|
};
|
|
121
140
|
if (priority === 'low' && !_utils.IS_SSR) {
|
|
122
141
|
return function (props) {
|
|
@@ -132,13 +151,16 @@ function createAlfaWidget(option) {
|
|
|
132
151
|
delayPromise: delayPromise,
|
|
133
152
|
style: props.style || passedInOption.style,
|
|
134
153
|
deps: dependencies || {},
|
|
135
|
-
customProps: _objectSpread({}, props)
|
|
136
|
-
|
|
154
|
+
customProps: _objectSpread({}, props)
|
|
155
|
+
// 低优先级下,不预加载
|
|
156
|
+
,
|
|
157
|
+
preLoader: undefined
|
|
137
158
|
}))));
|
|
138
159
|
};
|
|
139
160
|
}
|
|
140
161
|
return function (props) {
|
|
141
162
|
var delayPromise = useDelay();
|
|
163
|
+
initialized = true;
|
|
142
164
|
|
|
143
165
|
// Compatible with old logic
|
|
144
166
|
// props should not passed in errorBoundary
|
|
@@ -147,7 +169,7 @@ function createAlfaWidget(option) {
|
|
|
147
169
|
style: props.style || passedInOption.style,
|
|
148
170
|
deps: dependencies || {},
|
|
149
171
|
customProps: _objectSpread({}, props),
|
|
150
|
-
preLoader:
|
|
172
|
+
preLoader: register
|
|
151
173
|
})));
|
|
152
174
|
};
|
|
153
175
|
}
|
package/lib/createApplication.js
CHANGED
|
@@ -68,6 +68,7 @@ function createApplication(loader) {
|
|
|
68
68
|
basename = props.basename,
|
|
69
69
|
channel = props.channel,
|
|
70
70
|
delayPromise = props.delayPromise,
|
|
71
|
+
forceLog = props.forceLog,
|
|
71
72
|
preLoader = props.preLoader;
|
|
72
73
|
var handleExternalLink = customProps.handleExternalLink;
|
|
73
74
|
var _useState = (0, _react.useState)(null),
|
|
@@ -93,6 +94,7 @@ function createApplication(loader) {
|
|
|
93
94
|
preLoader: preLoader,
|
|
94
95
|
container: container
|
|
95
96
|
});
|
|
97
|
+
console.log('createApplication');
|
|
96
98
|
var onSyncHistory = (0, _hooks.useCallbackRef)(props.onSyncHistory || function () {});
|
|
97
99
|
$syncHistory.current = syncHistory;
|
|
98
100
|
$basename.current = basename;
|
|
@@ -289,7 +291,8 @@ function createApplication(loader) {
|
|
|
289
291
|
}
|
|
290
292
|
return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
|
|
291
293
|
E_CODE: 'RuntimeError',
|
|
292
|
-
E_MSG: 'load app failed.'
|
|
294
|
+
E_MSG: 'load app failed.',
|
|
295
|
+
__force_log__: forceLog
|
|
293
296
|
}));
|
|
294
297
|
case 24:
|
|
295
298
|
if (appRef.current) {
|
|
@@ -298,7 +301,8 @@ function createApplication(loader) {
|
|
|
298
301
|
}
|
|
299
302
|
return _context.abrupt("return", (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
|
|
300
303
|
E_CODE: 'RuntimeError',
|
|
301
|
-
E_MSG: 'cannot find container.'
|
|
304
|
+
E_MSG: 'cannot find container.',
|
|
305
|
+
__force_log__: forceLog
|
|
302
306
|
}));
|
|
303
307
|
case 26:
|
|
304
308
|
// update body in sandbox context
|
|
@@ -337,12 +341,13 @@ function createApplication(loader) {
|
|
|
337
341
|
window.history.go(n);
|
|
338
342
|
});
|
|
339
343
|
}
|
|
340
|
-
(logger === null || logger === void 0 ? void 0 : logger.record) &&
|
|
344
|
+
(logger === null || logger === void 0 ? void 0 : logger.record) && logger.record({
|
|
341
345
|
REQUEST_VERSION: memoOptions.version,
|
|
342
346
|
RESPONSE_VERSION: realVersion,
|
|
343
|
-
END_TIME: Date.now()
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
END_TIME: Date.now(),
|
|
348
|
+
__force_log__: forceLog
|
|
349
|
+
});
|
|
350
|
+
(logger === null || logger === void 0 ? void 0 : logger.send) && logger.send();
|
|
346
351
|
|
|
347
352
|
// just run once
|
|
348
353
|
setAppInstance(app);
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alicloud/alfa-react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3-alpha.0",
|
|
4
4
|
"description": "Alfa Framework (React Version)",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"lodash-es": "^4.17.21",
|
|
53
53
|
"prop-types": "^15.8.1",
|
|
54
54
|
"react-lazyload": "^3.2.1",
|
|
55
|
-
"@alicloud/alfa-core": "^1.5.
|
|
55
|
+
"@alicloud/alfa-core": "^1.5.5",
|
|
56
56
|
"@alicloud/console-os-loader": "^1.4.45-alpha.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
package/types/types/index.d.ts
CHANGED
|
@@ -74,6 +74,10 @@ export interface AlfaFactoryOption extends IAppConfig {
|
|
|
74
74
|
*/
|
|
75
75
|
scrollContainer?: string | Element | undefined;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* 强制上报日志
|
|
79
|
+
*/
|
|
80
|
+
forceLog?: boolean;
|
|
77
81
|
}
|
|
78
82
|
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T;
|
|
79
83
|
export type MicroApplication = ThenArg<ReturnType<typeof createMicroApp>>;
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.0.
|
|
1
|
+
export declare const version = "2.0.3-alpha.0";
|