@hhfenpm/micro-app 1.0.8 → 1.0.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/dist/index.esm.js CHANGED
@@ -54,7 +54,7 @@ const KEYS = [
54
54
  'get_version',
55
55
  ];
56
56
 
57
- function createCs(electron = {}) {
57
+ const createCs = (electron = {}) => {
58
58
  const base = Object.fromEntries(
59
59
  KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
60
60
  );
@@ -66,7 +66,7 @@ function createCs(electron = {}) {
66
66
  ? electron.is_app()
67
67
  : !!electron.is_app,
68
68
  }
69
- }
69
+ };
70
70
 
71
71
  const BRIDGE$1 = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
72
72
 
@@ -151,7 +151,7 @@ const createBaseObject = pending => {
151
151
  }
152
152
  };
153
153
 
154
- function createRegisterHandlers(getElectron) {
154
+ const createRegisterHandlers = getElectron => {
155
155
  const electron = (() => {
156
156
  try {
157
157
  return typeof getElectron === 'function' ? getElectron() : {}
@@ -160,7 +160,7 @@ function createRegisterHandlers(getElectron) {
160
160
  }
161
161
  })();
162
162
  return vm => ({ ui: uiHandler(vm), cs: createCs(electron) })
163
- }
163
+ };
164
164
 
165
165
  const initBridge = ({
166
166
  isBase = false,
@@ -224,10 +224,7 @@ const initBridge = ({
224
224
  });
225
225
  };
226
226
 
227
- function createMicroAppCore({
228
- modelMap,
229
- enabledModules,
230
- } = {}) {
227
+ const createMicroAppCore = ({ modelMap, enabledModules } = {}) => {
231
228
  if (!modelMap || typeof modelMap !== 'function') {
232
229
  throw new Error('modelMap function is required')
233
230
  }
@@ -262,7 +259,10 @@ function createMicroAppCore({
262
259
 
263
260
  const microAppDeployed = async module => {
264
261
  try {
265
- const res = await fetch(`/${module}`, { method: 'GET', cache: 'no-store' });
262
+ const res = await fetch(`/${module}`, {
263
+ method: 'GET',
264
+ cache: 'no-store',
265
+ });
266
266
  return res.ok
267
267
  } catch {
268
268
  return false
@@ -274,7 +274,27 @@ function createMicroAppCore({
274
274
  microAppSrc,
275
275
  microAppDeployed,
276
276
  }
277
- }
277
+ };
278
+
279
+ const mergeParentGlobalConfig = () => {
280
+ const getParentGlobalConfig = () => {
281
+ try {
282
+ if (
283
+ window.parent &&
284
+ window.parent !== window &&
285
+ window.parent.GLOBAL_CONFIG
286
+ ) {
287
+ return JSON.parse(JSON.stringify(window.parent.GLOBAL_CONFIG))
288
+ }
289
+ return null
290
+ } catch (e) {
291
+ return null
292
+ }
293
+ };
294
+ const parentGlobalConfig = getParentGlobalConfig();
295
+ if (parentGlobalConfig)
296
+ Object.assign(window.GLOBAL_CONFIG, parentGlobalConfig);
297
+ };
278
298
 
279
299
  const MESSAGE = {
280
300
  SYNC_FROM_CHILD: 'sync-base-from-child',
@@ -381,10 +401,10 @@ const createMessageHandlers = (
381
401
  return handlers
382
402
  };
383
403
 
384
- function baseSyncPlugin({
404
+ const baseSyncPlugin = ({
385
405
  isBase = false,
386
406
  iframeSelector = '#microApp',
387
- } = {}) {
407
+ } = {}) => {
388
408
  return store => {
389
409
  let latestBaseState = store.state.base;
390
410
  let isMounted = false;
@@ -477,9 +497,9 @@ function baseSyncPlugin({
477
497
 
478
498
  return store
479
499
  }
480
- }
500
+ };
481
501
 
482
- function syncState(watch = {}) {
502
+ const syncState = (watch = {}) => {
483
503
  return function SYNC_STATE(state, payload) {
484
504
  if (!payload || typeof payload !== 'object') return
485
505
 
@@ -495,6 +515,6 @@ function syncState(watch = {}) {
495
515
  if (state[key] !== payload[key]) state[key] = payload[key];
496
516
  });
497
517
  }
498
- }
518
+ };
499
519
 
500
- export { baseSyncPlugin, createMicroAppCore, createRegisterHandlers, initBridge, syncState };
520
+ export { baseSyncPlugin, createMicroAppCore, createRegisterHandlers, initBridge, mergeParentGlobalConfig, syncState };
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ const KEYS = [
56
56
  'get_version',
57
57
  ];
58
58
 
59
- function createCs(electron = {}) {
59
+ const createCs = (electron = {}) => {
60
60
  const base = Object.fromEntries(
61
61
  KEYS.map(k => [k, typeof electron[k] === 'function' ? electron[k] : noop])
62
62
  );
@@ -68,7 +68,7 @@ function createCs(electron = {}) {
68
68
  ? electron.is_app()
69
69
  : !!electron.is_app,
70
70
  }
71
- }
71
+ };
72
72
 
73
73
  const BRIDGE$1 = { INVOKE: 'bridge-invoke', CALLBACK: 'bridge-callback' };
74
74
 
@@ -153,7 +153,7 @@ const createBaseObject = pending => {
153
153
  }
154
154
  };
155
155
 
156
- function createRegisterHandlers(getElectron) {
156
+ const createRegisterHandlers = getElectron => {
157
157
  const electron = (() => {
158
158
  try {
159
159
  return typeof getElectron === 'function' ? getElectron() : {}
@@ -162,7 +162,7 @@ function createRegisterHandlers(getElectron) {
162
162
  }
163
163
  })();
164
164
  return vm => ({ ui: uiHandler(vm), cs: createCs(electron) })
165
- }
165
+ };
166
166
 
167
167
  const initBridge = ({
168
168
  isBase = false,
@@ -226,10 +226,7 @@ const initBridge = ({
226
226
  });
227
227
  };
228
228
 
229
- function createMicroAppCore({
230
- modelMap,
231
- enabledModules,
232
- } = {}) {
229
+ const createMicroAppCore = ({ modelMap, enabledModules } = {}) => {
233
230
  if (!modelMap || typeof modelMap !== 'function') {
234
231
  throw new Error('modelMap function is required')
235
232
  }
@@ -264,7 +261,10 @@ function createMicroAppCore({
264
261
 
265
262
  const microAppDeployed = async module => {
266
263
  try {
267
- const res = await fetch(`/${module}`, { method: 'GET', cache: 'no-store' });
264
+ const res = await fetch(`/${module}`, {
265
+ method: 'GET',
266
+ cache: 'no-store',
267
+ });
268
268
  return res.ok
269
269
  } catch {
270
270
  return false
@@ -276,7 +276,27 @@ function createMicroAppCore({
276
276
  microAppSrc,
277
277
  microAppDeployed,
278
278
  }
279
- }
279
+ };
280
+
281
+ const mergeParentGlobalConfig = () => {
282
+ const getParentGlobalConfig = () => {
283
+ try {
284
+ if (
285
+ window.parent &&
286
+ window.parent !== window &&
287
+ window.parent.GLOBAL_CONFIG
288
+ ) {
289
+ return JSON.parse(JSON.stringify(window.parent.GLOBAL_CONFIG))
290
+ }
291
+ return null
292
+ } catch (e) {
293
+ return null
294
+ }
295
+ };
296
+ const parentGlobalConfig = getParentGlobalConfig();
297
+ if (parentGlobalConfig)
298
+ Object.assign(window.GLOBAL_CONFIG, parentGlobalConfig);
299
+ };
280
300
 
281
301
  const MESSAGE = {
282
302
  SYNC_FROM_CHILD: 'sync-base-from-child',
@@ -383,10 +403,10 @@ const createMessageHandlers = (
383
403
  return handlers
384
404
  };
385
405
 
386
- function baseSyncPlugin({
406
+ const baseSyncPlugin = ({
387
407
  isBase = false,
388
408
  iframeSelector = '#microApp',
389
- } = {}) {
409
+ } = {}) => {
390
410
  return store => {
391
411
  let latestBaseState = store.state.base;
392
412
  let isMounted = false;
@@ -479,9 +499,9 @@ function baseSyncPlugin({
479
499
 
480
500
  return store
481
501
  }
482
- }
502
+ };
483
503
 
484
- function syncState(watch = {}) {
504
+ const syncState = (watch = {}) => {
485
505
  return function SYNC_STATE(state, payload) {
486
506
  if (!payload || typeof payload !== 'object') return
487
507
 
@@ -497,10 +517,11 @@ function syncState(watch = {}) {
497
517
  if (state[key] !== payload[key]) state[key] = payload[key];
498
518
  });
499
519
  }
500
- }
520
+ };
501
521
 
502
522
  exports.baseSyncPlugin = baseSyncPlugin;
503
523
  exports.createMicroAppCore = createMicroAppCore;
504
524
  exports.createRegisterHandlers = createRegisterHandlers;
505
525
  exports.initBridge = initBridge;
526
+ exports.mergeParentGlobalConfig = mergeParentGlobalConfig;
506
527
  exports.syncState = syncState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hhfenpm/micro-app",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "微前端通信桥接和状态同步工具,支持父子应用通信、状态同步、生命周期管理",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",