@micro-zoe/micro-app 1.0.0-rc.7 → 1.0.0-rc.8

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/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.7';
1
+ const version = '1.0.0-rc.8';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -4065,32 +4065,34 @@ function createMicroHistory(appName, microLocation) {
4065
4065
  (_c = (_a = appInstanceMap.get(appName)) === null || _a === void 0 ? void 0 : (_b = _a.sandBox).updateIframeBase) === null || _c === void 0 ? void 0 : _c.call(_b);
4066
4066
  };
4067
4067
  }
4068
- const pushState = getMicroHistoryMethod('pushState');
4069
- const replaceState = getMicroHistoryMethod('replaceState');
4068
+ const originalHistory = {
4069
+ pushState: getMicroHistoryMethod('pushState'),
4070
+ replaceState: getMicroHistoryMethod('replaceState'),
4071
+ };
4070
4072
  if (isIframeSandbox(appName)) {
4071
- return {
4072
- pushState,
4073
- replaceState,
4073
+ return assign({
4074
4074
  go(delta) {
4075
4075
  return rawHistory.go(delta);
4076
4076
  }
4077
- };
4077
+ }, originalHistory);
4078
4078
  }
4079
4079
  return new Proxy(rawHistory, {
4080
4080
  get(target, key) {
4081
- if (key === 'state') {
4082
- return getMicroState(appName);
4083
- }
4084
- else if (key === 'pushState') {
4085
- return pushState;
4081
+ if (key === 'pushState' || key === 'replaceState') {
4082
+ return originalHistory[key];
4086
4083
  }
4087
- else if (key === 'replaceState') {
4088
- return replaceState;
4084
+ else if (key === 'state') {
4085
+ return getMicroState(appName);
4089
4086
  }
4090
4087
  return bindFunctionToRawTarget(Reflect.get(target, key), target, 'HISTORY');
4091
4088
  },
4092
4089
  set(target, key, value) {
4093
- Reflect.set(target, key, value);
4090
+ if (key === 'pushState' || key === 'replaceState') {
4091
+ originalHistory[key] = value;
4092
+ }
4093
+ else {
4094
+ Reflect.set(target, key, value);
4095
+ }
4094
4096
  /**
4095
4097
  * If the set() method returns false, and the assignment happened in strict-mode code, a TypeError will be thrown.
4096
4098
  * e.g. history.state = {}
@@ -4186,7 +4188,6 @@ function reWriteHistoryMethod(method) {
4186
4188
  excludeHiddenApp: true,
4187
4189
  excludePreRender: true,
4188
4190
  }).forEach(appName => {
4189
- // TODO: 大部分情况下,history.pushState 都是先执行,micro-app后卸载,所以会产生一种情况:跳转到新地址后,search模式会在url上添加参数,卸载后再将参数删除,所以会导致浏览器地址闪烁,是否需要去掉这个功能
4190
4191
  if ((isRouterModeSearch(appName) || isRouterModeState(appName)) && !getMicroPathFromURL(appName)) {
4191
4192
  const app = appInstanceMap.get(appName);
4192
4193
  attachRouteToBrowserURL(appName, setMicroPathToURL(appName, app.sandBox.proxyWindow.location), setMicroState(appName, getMicroState(appName), app.sandBox.proxyWindow.location));
@@ -8283,8 +8284,7 @@ function defineElement(tagName) {
8283
8284
  if (this.legalAttribute(attr, newVal) &&
8284
8285
  this[attr === ObservedAttrName.NAME ? 'appName' : 'appUrl'] !== newVal) {
8285
8286
  if (attr === ObservedAttrName.URL && (!this.appUrl ||
8286
- !this.connectStateMap.get(this.connectedCount) // TODO: 这里的逻辑可否再优化一下
8287
- )) {
8287
+ !this.connectStateMap.get(this.connectedCount))) {
8288
8288
  newVal = formatAppURL(newVal, this.appName);
8289
8289
  if (!newVal) {
8290
8290
  return logError(`Invalid attribute url ${newVal}`, this.appName);
@@ -8293,13 +8293,11 @@ function defineElement(tagName) {
8293
8293
  this.handleInitialNameAndUrl();
8294
8294
  }
8295
8295
  else if (attr === ObservedAttrName.NAME && (!this.appName ||
8296
- !this.connectStateMap.get(this.connectedCount) // TODO: 这里的逻辑可否再优化一下
8297
- )) {
8296
+ !this.connectStateMap.get(this.connectedCount))) {
8298
8297
  const formatNewName = formatAppName(newVal);
8299
8298
  if (!formatNewName) {
8300
8299
  return logError(`Invalid attribute name ${newVal}`, this.appName);
8301
8300
  }
8302
- // TODO: 当micro-app还未插入文档中就修改name,逻辑可否再优化一下
8303
8301
  if (this.cacheData) {
8304
8302
  microApp.setData(formatNewName, this.cacheData);
8305
8303
  this.cacheData = null;