@alicloud/alfa-react 2.0.2 → 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.
@@ -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 preLoader;
64
- if (priority === 'high' && !IS_SSR) {
65
- var p = loader.register(_objectSpread(_objectSpread({}, option), {}, {
66
- // 必须设置 container,否则沙箱会创建插入一个新的 body
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(function () {
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
- preLoader: preLoader
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: preLoader
160
+ preLoader: register
139
161
  })));
140
162
  };
141
163
  }
@@ -84,6 +84,7 @@ export default function createApplication(loader) {
84
84
  preLoader: preLoader,
85
85
  container: container
86
86
  });
87
+ console.log('createApplication');
87
88
  var onSyncHistory = useCallbackRef(props.onSyncHistory || function () {});
88
89
  $syncHistory.current = syncHistory;
89
90
  $basename.current = basename;
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '2.0.2';
1
+ export var version = '2.0.3-alpha.0';
@@ -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 preLoader;
76
- if (priority === 'high' && !_utils.IS_SSR) {
77
- var p = loader.register(_objectSpread(_objectSpread({}, option), {}, {
78
- // 必须设置 container,否则沙箱会创建插入一个新的 body
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)(function () {
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
- preLoader: preLoader
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: preLoader
172
+ preLoader: register
151
173
  })));
152
174
  };
153
175
  }
@@ -94,6 +94,7 @@ function createApplication(loader) {
94
94
  preLoader: preLoader,
95
95
  container: container
96
96
  });
97
+ console.log('createApplication');
97
98
  var onSyncHistory = (0, _hooks.useCallbackRef)(props.onSyncHistory || function () {});
98
99
  $syncHistory.current = syncHistory;
99
100
  $basename.current = basename;
package/lib/version.js CHANGED
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- var version = exports.version = '2.0.2';
7
+ var version = exports.version = '2.0.3-alpha.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-react",
3
- "version": "2.0.2",
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.3",
55
+ "@alicloud/alfa-core": "^1.5.5",
56
56
  "@alicloud/console-os-loader": "^1.4.45-alpha.1"
57
57
  },
58
58
  "peerDependencies": {
@@ -1 +1 @@
1
- export declare const version = "2.0.2";
1
+ export declare const version = "2.0.3-alpha.0";