@zstackui/qiankun 2.6.3-beta-5

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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -0
  3. package/dist/index.umd.js +8681 -0
  4. package/dist/index.umd.js.map +1 -0
  5. package/dist/index.umd.min.js +4 -0
  6. package/dist/index.umd.min.js.map +1 -0
  7. package/dist/src/__tests__/globalState.test.d.ts +5 -0
  8. package/dist/src/__tests__/utils.test.d.ts +1 -0
  9. package/dist/src/addons/engineFlag.d.ts +6 -0
  10. package/dist/src/addons/index.d.ts +6 -0
  11. package/dist/src/addons/runtimePublicPath.d.ts +6 -0
  12. package/dist/src/apis.d.ts +7 -0
  13. package/dist/src/effects.d.ts +3 -0
  14. package/dist/src/error.d.ts +3 -0
  15. package/dist/src/errorHandler.d.ts +7 -0
  16. package/dist/src/globalState.d.ts +7 -0
  17. package/dist/src/index.d.ts +11 -0
  18. package/dist/src/interfaces.d.ts +107 -0
  19. package/dist/src/loader.d.ts +8 -0
  20. package/dist/src/prefetch.d.ts +14 -0
  21. package/dist/src/sandbox/__tests__/common.test.d.ts +5 -0
  22. package/dist/src/sandbox/__tests__/proxySandbox.test.d.ts +10 -0
  23. package/dist/src/sandbox/common.d.ts +21 -0
  24. package/dist/src/sandbox/index.d.ts +40 -0
  25. package/dist/src/sandbox/legacy/__tests__/sandbox.test.d.ts +5 -0
  26. package/dist/src/sandbox/legacy/sandbox.d.ts +28 -0
  27. package/dist/src/sandbox/patchers/__tests__/css.test.d.ts +5 -0
  28. package/dist/src/sandbox/patchers/__tests__/interval.test.d.ts +5 -0
  29. package/dist/src/sandbox/patchers/css.d.ts +17 -0
  30. package/dist/src/sandbox/patchers/dynamicAppend/__tests__/common.test.d.ts +1 -0
  31. package/dist/src/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  32. package/dist/src/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  33. package/dist/src/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  34. package/dist/src/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  35. package/dist/src/sandbox/patchers/historyListener.d.ts +5 -0
  36. package/dist/src/sandbox/patchers/index.d.ts +9 -0
  37. package/dist/src/sandbox/patchers/interval.d.ts +5 -0
  38. package/dist/src/sandbox/patchers/windowListener.d.ts +5 -0
  39. package/dist/src/sandbox/proxySandbox.d.ts +23 -0
  40. package/dist/src/sandbox/snapshotSandbox.d.ts +20 -0
  41. package/dist/src/utils.d.ts +44 -0
  42. package/dist/src/version.d.ts +1 -0
  43. package/es/addons/engineFlag.d.ts +6 -0
  44. package/es/addons/engineFlag.js +50 -0
  45. package/es/addons/index.d.ts +6 -0
  46. package/es/addons/index.js +13 -0
  47. package/es/addons/runtimePublicPath.d.ts +6 -0
  48. package/es/addons/runtimePublicPath.js +57 -0
  49. package/es/apis.d.ts +7 -0
  50. package/es/apis.js +278 -0
  51. package/es/effects.d.ts +3 -0
  52. package/es/effects.js +33 -0
  53. package/es/error.d.ts +3 -0
  54. package/es/error.js +16 -0
  55. package/es/errorHandler.d.ts +7 -0
  56. package/es/errorHandler.js +13 -0
  57. package/es/globalState.d.ts +7 -0
  58. package/es/globalState.js +101 -0
  59. package/es/index.d.ts +11 -0
  60. package/es/index.js +11 -0
  61. package/es/interfaces.d.ts +107 -0
  62. package/es/interfaces.js +8 -0
  63. package/es/loader.d.ts +8 -0
  64. package/es/loader.js +600 -0
  65. package/es/prefetch.d.ts +14 -0
  66. package/es/prefetch.js +125 -0
  67. package/es/sandbox/common.d.ts +21 -0
  68. package/es/sandbox/common.js +157 -0
  69. package/es/sandbox/index.d.ts +40 -0
  70. package/es/sandbox/index.js +105 -0
  71. package/es/sandbox/legacy/sandbox.d.ts +28 -0
  72. package/es/sandbox/legacy/sandbox.js +142 -0
  73. package/es/sandbox/patchers/css.d.ts +17 -0
  74. package/es/sandbox/patchers/css.js +186 -0
  75. package/es/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  76. package/es/sandbox/patchers/dynamicAppend/common.js +306 -0
  77. package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  78. package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.js +77 -0
  79. package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  80. package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.js +103 -0
  81. package/es/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  82. package/es/sandbox/patchers/dynamicAppend/index.js +6 -0
  83. package/es/sandbox/patchers/historyListener.d.ts +5 -0
  84. package/es/sandbox/patchers/historyListener.js +54 -0
  85. package/es/sandbox/patchers/index.d.ts +9 -0
  86. package/es/sandbox/patchers/index.js +45 -0
  87. package/es/sandbox/patchers/interval.d.ts +5 -0
  88. package/es/sandbox/patchers/interval.js +34 -0
  89. package/es/sandbox/patchers/windowListener.d.ts +5 -0
  90. package/es/sandbox/patchers/windowListener.js +34 -0
  91. package/es/sandbox/proxySandbox.d.ts +23 -0
  92. package/es/sandbox/proxySandbox.js +315 -0
  93. package/es/sandbox/snapshotSandbox.d.ts +20 -0
  94. package/es/sandbox/snapshotSandbox.js +59 -0
  95. package/es/utils.d.ts +44 -0
  96. package/es/utils.js +215 -0
  97. package/es/version.d.ts +1 -0
  98. package/es/version.js +1 -0
  99. package/lib/addons/engineFlag.d.ts +6 -0
  100. package/lib/addons/engineFlag.js +55 -0
  101. package/lib/addons/index.d.ts +6 -0
  102. package/lib/addons/index.js +21 -0
  103. package/lib/addons/runtimePublicPath.d.ts +6 -0
  104. package/lib/addons/runtimePublicPath.js +63 -0
  105. package/lib/apis.d.ts +7 -0
  106. package/lib/apis.js +288 -0
  107. package/lib/effects.d.ts +3 -0
  108. package/lib/effects.js +42 -0
  109. package/lib/error.d.ts +3 -0
  110. package/lib/error.js +23 -0
  111. package/lib/errorHandler.d.ts +7 -0
  112. package/lib/errorHandler.js +33 -0
  113. package/lib/globalState.d.ts +7 -0
  114. package/lib/globalState.js +110 -0
  115. package/lib/index.d.ts +11 -0
  116. package/lib/index.js +89 -0
  117. package/lib/interfaces.d.ts +107 -0
  118. package/lib/interfaces.js +14 -0
  119. package/lib/loader.d.ts +8 -0
  120. package/lib/loader.js +606 -0
  121. package/lib/prefetch.d.ts +14 -0
  122. package/lib/prefetch.js +132 -0
  123. package/lib/sandbox/common.d.ts +21 -0
  124. package/lib/sandbox/common.js +169 -0
  125. package/lib/sandbox/index.d.ts +40 -0
  126. package/lib/sandbox/index.js +123 -0
  127. package/lib/sandbox/legacy/sandbox.d.ts +28 -0
  128. package/lib/sandbox/legacy/sandbox.js +148 -0
  129. package/lib/sandbox/patchers/css.d.ts +17 -0
  130. package/lib/sandbox/patchers/css.js +193 -0
  131. package/lib/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  132. package/lib/sandbox/patchers/dynamicAppend/common.js +322 -0
  133. package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  134. package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.js +84 -0
  135. package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  136. package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.js +110 -0
  137. package/lib/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  138. package/lib/sandbox/patchers/dynamicAppend/index.js +19 -0
  139. package/lib/sandbox/patchers/historyListener.d.ts +5 -0
  140. package/lib/sandbox/patchers/historyListener.js +62 -0
  141. package/lib/sandbox/patchers/index.d.ts +9 -0
  142. package/lib/sandbox/patchers/index.js +57 -0
  143. package/lib/sandbox/patchers/interval.d.ts +5 -0
  144. package/lib/sandbox/patchers/interval.js +42 -0
  145. package/lib/sandbox/patchers/windowListener.d.ts +5 -0
  146. package/lib/sandbox/patchers/windowListener.js +42 -0
  147. package/lib/sandbox/proxySandbox.d.ts +23 -0
  148. package/lib/sandbox/proxySandbox.js +321 -0
  149. package/lib/sandbox/snapshotSandbox.d.ts +20 -0
  150. package/lib/sandbox/snapshotSandbox.js +65 -0
  151. package/lib/utils.d.ts +44 -0
  152. package/lib/utils.js +240 -0
  153. package/lib/version.d.ts +1 -0
  154. package/lib/version.js +7 -0
  155. package/package.json +137 -0
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.doPrefetchStrategy = doPrefetchStrategy;
8
+ exports.prefetchImmediately = prefetchImmediately;
9
+ var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
10
+ var _tslib = require("tslib");
11
+ var _importHtmlEntry = require("import-html-entry");
12
+ var _singleSpa = require("single-spa");
13
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
14
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } /**
15
+ * @author Kuitos
16
+ * @since 2019-02-26
17
+ */
18
+ // RIC and shim for browsers setTimeout() without it
19
+ var requestIdleCallback = window.requestIdleCallback || function requestIdleCallback(cb) {
20
+ var start = Date.now();
21
+ return setTimeout(function () {
22
+ cb({
23
+ didTimeout: false,
24
+ timeRemaining: function timeRemaining() {
25
+ return Math.max(0, 50 - (Date.now() - start));
26
+ }
27
+ });
28
+ }, 1);
29
+ };
30
+ var isSlowNetwork = navigator.connection ? navigator.connection.saveData || navigator.connection.type !== 'wifi' && navigator.connection.type !== 'ethernet' && /([23])g/.test(navigator.connection.effectiveType) : false;
31
+ /**
32
+ * prefetch assets, do nothing while in mobile network
33
+ * @param entry
34
+ * @param opts
35
+ */
36
+ function prefetch(entry, opts) {
37
+ var _this = this;
38
+ if (!navigator.onLine || isSlowNetwork) {
39
+ // Don't prefetch if in a slow network or offline
40
+ return;
41
+ }
42
+ requestIdleCallback(function () {
43
+ return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
44
+ var _yield$importEntry, getExternalScripts, getExternalStyleSheets;
45
+ return _regenerator().w(function (_context) {
46
+ while (1) switch (_context.n) {
47
+ case 0:
48
+ _context.n = 1;
49
+ return (0, _importHtmlEntry.importEntry)(entry, opts);
50
+ case 1:
51
+ _yield$importEntry = _context.v;
52
+ getExternalScripts = _yield$importEntry.getExternalScripts;
53
+ getExternalStyleSheets = _yield$importEntry.getExternalStyleSheets;
54
+ requestIdleCallback(getExternalStyleSheets);
55
+ requestIdleCallback(getExternalScripts);
56
+ case 2:
57
+ return _context.a(2);
58
+ }
59
+ }, _callee);
60
+ }));
61
+ });
62
+ }
63
+ function prefetchAfterFirstMounted(apps, opts) {
64
+ window.addEventListener('single-spa:first-mount', function listener() {
65
+ var notLoadedApps = apps.filter(function (app) {
66
+ return (0, _singleSpa.getAppStatus)(app.name) === _singleSpa.NOT_LOADED;
67
+ });
68
+ if (process.env.NODE_ENV === 'development') {
69
+ var mountedApps = (0, _singleSpa.getMountedApps)();
70
+ console.log("[qiankun] prefetch starting after ".concat(mountedApps, " mounted..."), notLoadedApps);
71
+ }
72
+ notLoadedApps.forEach(function (_ref) {
73
+ var entry = _ref.entry;
74
+ return prefetch(entry, opts);
75
+ });
76
+ window.removeEventListener('single-spa:first-mount', listener);
77
+ });
78
+ }
79
+ function prefetchImmediately(apps, opts) {
80
+ if (process.env.NODE_ENV === 'development') {
81
+ console.log('[qiankun] prefetch starting for apps...', apps);
82
+ }
83
+ apps.forEach(function (_ref2) {
84
+ var entry = _ref2.entry;
85
+ return prefetch(entry, opts);
86
+ });
87
+ }
88
+ function doPrefetchStrategy(apps, prefetchStrategy, importEntryOpts) {
89
+ var _this2 = this;
90
+ var appsName2Apps = function appsName2Apps(names) {
91
+ return apps.filter(function (app) {
92
+ return names.includes(app.name);
93
+ });
94
+ };
95
+ if (Array.isArray(prefetchStrategy)) {
96
+ prefetchAfterFirstMounted(appsName2Apps(prefetchStrategy), importEntryOpts);
97
+ } else if ((0, _isFunction2.default)(prefetchStrategy)) {
98
+ (function () {
99
+ return (0, _tslib.__awaiter)(_this2, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
100
+ var _yield$prefetchStrate, _yield$prefetchStrate2, criticalAppNames, _yield$prefetchStrate3, minorAppsName;
101
+ return _regenerator().w(function (_context2) {
102
+ while (1) switch (_context2.n) {
103
+ case 0:
104
+ _context2.n = 1;
105
+ return prefetchStrategy(apps);
106
+ case 1:
107
+ _yield$prefetchStrate = _context2.v;
108
+ _yield$prefetchStrate2 = _yield$prefetchStrate.criticalAppNames;
109
+ criticalAppNames = _yield$prefetchStrate2 === void 0 ? [] : _yield$prefetchStrate2;
110
+ _yield$prefetchStrate3 = _yield$prefetchStrate.minorAppsName;
111
+ minorAppsName = _yield$prefetchStrate3 === void 0 ? [] : _yield$prefetchStrate3;
112
+ prefetchImmediately(appsName2Apps(criticalAppNames), importEntryOpts);
113
+ prefetchAfterFirstMounted(appsName2Apps(minorAppsName), importEntryOpts);
114
+ case 2:
115
+ return _context2.a(2);
116
+ }
117
+ }, _callee2);
118
+ }));
119
+ })();
120
+ } else {
121
+ switch (prefetchStrategy) {
122
+ case true:
123
+ prefetchAfterFirstMounted(apps, importEntryOpts);
124
+ break;
125
+ case 'all':
126
+ prefetchImmediately(apps, importEntryOpts);
127
+ break;
128
+ default:
129
+ break;
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2020-04-13
4
+ */
5
+ type AppInstance = {
6
+ name: string;
7
+ window: WindowProxy;
8
+ };
9
+ /**
10
+ * get the app that running tasks at current tick
11
+ */
12
+ export declare function getCurrentRunningApp(): AppInstance | null;
13
+ export declare function setCurrentRunningApp(appInstance: {
14
+ name: string;
15
+ window: WindowProxy;
16
+ } | null): void;
17
+ export declare function getTargetValue(target: any, value: any): any;
18
+ export declare function getProxyPropertyValue(getter: CallableFunction): any;
19
+ export declare function getZsLocalStorage(_proxyName: string): any;
20
+ export declare function getZsSessionStorage(_proxyName: string): any;
21
+ export {};
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCurrentRunningApp = getCurrentRunningApp;
7
+ exports.getProxyPropertyValue = getProxyPropertyValue;
8
+ exports.getTargetValue = getTargetValue;
9
+ exports.getZsLocalStorage = getZsLocalStorage;
10
+ exports.getZsSessionStorage = getZsSessionStorage;
11
+ exports.setCurrentRunningApp = setCurrentRunningApp;
12
+ var _utils = require("../utils");
13
+ /**
14
+ * @author Kuitos
15
+ * @since 2020-04-13
16
+ */
17
+
18
+ var currentRunningApp = null;
19
+ /**
20
+ * get the app that running tasks at current tick
21
+ */
22
+ function getCurrentRunningApp() {
23
+ return currentRunningApp;
24
+ }
25
+ function setCurrentRunningApp(appInstance) {
26
+ // set currentRunningApp and it's proxySandbox to global window, as its only use case is for document.createElement from now on, which hijacked by a global way
27
+ currentRunningApp = appInstance;
28
+ }
29
+ var functionBoundedValueMap = new WeakMap();
30
+ function getTargetValue(target, _value) {
31
+ /*
32
+ 仅绑定 isCallable && !isBoundedFunction && !isConstructable 的函数对象,如 window.console、window.atob 这类,不然微应用中调用时会抛出 Illegal invocation 异常
33
+ 目前没有完美的检测方式,这里通过 prototype 中是否还有可枚举的拓展方法的方式来判断
34
+ @warning 这里不要随意替换成别的判断方式,因为可能触发一些 edge case(比如在 lodash.isFunction 在 iframe 上下文中可能由于调用了 top window 对象触发的安全异常)
35
+ */
36
+ if ((0, _utils.isCallable)(_value) && !(0, _utils.isBoundedFunction)(_value) && !(0, _utils.isConstructable)(_value)) {
37
+ var cachedBoundFunction = functionBoundedValueMap.get(_value);
38
+ if (cachedBoundFunction) {
39
+ return cachedBoundFunction;
40
+ }
41
+ var boundValue = Function.prototype.bind.call(_value, target);
42
+ // some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function.
43
+ // use for..in rather than Object.keys.forEach for performance reason
44
+ // eslint-disable-next-line guard-for-in,no-restricted-syntax
45
+ for (var key in _value) {
46
+ boundValue[key] = _value[key];
47
+ }
48
+ // copy prototype if bound function not have but target one have
49
+ // as prototype is non-enumerable mostly, we need to copy it from target function manually
50
+ if (_value.hasOwnProperty('prototype') && !boundValue.hasOwnProperty('prototype')) {
51
+ // we should not use assignment operator to set boundValue prototype like `boundValue.prototype = value.prototype`
52
+ // as the assignment will also look up prototype chain while it hasn't own prototype property,
53
+ // when the lookup succeed, the assignment will throw an TypeError like `Cannot assign to read only property 'prototype' of function` if its descriptor configured with writable false or just have a getter accessor
54
+ // see https://github.com/umijs/qiankun/issues/1121
55
+ Object.defineProperty(boundValue, 'prototype', {
56
+ value: _value.prototype,
57
+ enumerable: false,
58
+ writable: true
59
+ });
60
+ }
61
+ // Some util, like `function isNative() { return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) }` relies on the original `toString()` result
62
+ // but bound functions will always return "function() {[native code]}" for `toString`, which is misleading
63
+ if (typeof _value.toString === 'function') {
64
+ var valueHasInstanceToString = _value.hasOwnProperty('toString') && !boundValue.hasOwnProperty('toString');
65
+ var boundValueHasPrototypeToString = boundValue.toString === Function.prototype.toString;
66
+ if (valueHasInstanceToString || boundValueHasPrototypeToString) {
67
+ var originToStringDescriptor = Object.getOwnPropertyDescriptor(valueHasInstanceToString ? _value : Function.prototype, 'toString');
68
+ Object.defineProperty(boundValue, 'toString', Object.assign(Object.assign({}, originToStringDescriptor), (originToStringDescriptor === null || originToStringDescriptor === void 0 ? void 0 : originToStringDescriptor.get) ? null : {
69
+ value: function value() {
70
+ return _value.toString();
71
+ }
72
+ }));
73
+ }
74
+ }
75
+ functionBoundedValueMap.set(_value, boundValue);
76
+ return boundValue;
77
+ }
78
+ return _value;
79
+ }
80
+ var getterInvocationResultMap = new WeakMap();
81
+ function getProxyPropertyValue(getter) {
82
+ var getterResult = getterInvocationResultMap.get(getter);
83
+ if (!getterResult) {
84
+ var result = getter();
85
+ getterInvocationResultMap.set(getter, result);
86
+ return result;
87
+ }
88
+ return getterResult;
89
+ }
90
+ function getZsLocalStorage(_proxyName) {
91
+ var proxyName = _proxyName.split('_')[0];
92
+ var fakeStorage = {
93
+ getItem: function getItem(key) {
94
+ var prefixedKey = proxyName + key;
95
+ return localStorage.getItem(prefixedKey);
96
+ },
97
+ setItem: function setItem(key, value) {
98
+ var prefixedKey = proxyName + key;
99
+ localStorage.setItem(prefixedKey, String(value));
100
+ },
101
+ key: function key(nth) {
102
+ var _a;
103
+ return (_a = localStorage.key(nth)) === null || _a === void 0 ? void 0 : _a.slice(proxyName.length);
104
+ },
105
+ removeItem: function removeItem(key) {
106
+ var prefixedKey = proxyName + key;
107
+ localStorage.removeItem(prefixedKey);
108
+ },
109
+ clear: function clear() {
110
+ var keysToRemove = [];
111
+ for (var i = 0; i < localStorage.length; i += 1) {
112
+ var key = localStorage.key(i);
113
+ if (key && key.startsWith(proxyName)) {
114
+ keysToRemove.push(key);
115
+ }
116
+ }
117
+ keysToRemove.forEach(function (key) {
118
+ localStorage.removeItem(key);
119
+ });
120
+ }
121
+ };
122
+ var proxy = new Proxy({}, {
123
+ get: function get(_, p) {
124
+ var _a;
125
+ return (_a = fakeStorage[p]) !== null && _a !== void 0 ? _a : localStorage[p];
126
+ }
127
+ });
128
+ return proxy;
129
+ }
130
+ function getZsSessionStorage(_proxyName) {
131
+ var proxyName = _proxyName.split('_')[0];
132
+ var fakeStorage = {
133
+ getItem: function getItem(key) {
134
+ var prefixedKey = proxyName + key;
135
+ return sessionStorage.getItem(prefixedKey);
136
+ },
137
+ key: function key(nth) {
138
+ var _a;
139
+ return (_a = sessionStorage.key(nth)) === null || _a === void 0 ? void 0 : _a.slice(proxyName.length);
140
+ },
141
+ setItem: function setItem(key, value) {
142
+ var prefixedKey = proxyName + key;
143
+ sessionStorage.setItem(prefixedKey, String(value));
144
+ },
145
+ removeItem: function removeItem(key) {
146
+ var prefixedKey = proxyName + key;
147
+ sessionStorage.removeItem(prefixedKey);
148
+ },
149
+ clear: function clear() {
150
+ var keysToRemove = [];
151
+ for (var i = 0; i < sessionStorage.length; i += 1) {
152
+ var key = sessionStorage.key(i);
153
+ if (key && key.startsWith(proxyName)) {
154
+ keysToRemove.push(key);
155
+ }
156
+ }
157
+ keysToRemove.forEach(function (key) {
158
+ sessionStorage.removeItem(key);
159
+ });
160
+ }
161
+ };
162
+ var proxy = new Proxy({}, {
163
+ get: function get(_, p) {
164
+ var _a;
165
+ return (_a = fakeStorage[p]) !== null && _a !== void 0 ? _a : sessionStorage[p];
166
+ }
167
+ });
168
+ return proxy;
169
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-04-11
4
+ */
5
+ import type { SandBox } from '../interfaces';
6
+ export { css } from './patchers';
7
+ export { getCurrentRunningApp } from './common';
8
+ /**
9
+ * 生成应用运行时沙箱
10
+ *
11
+ * 沙箱分两个类型:
12
+ * 1. app 环境沙箱
13
+ * app 环境沙箱是指应用初始化过之后,应用会在什么样的上下文环境运行。每个应用的环境沙箱只会初始化一次,因为子应用只会触发一次 bootstrap 。
14
+ * 子应用在切换时,实际上切换的是 app 环境沙箱。
15
+ * 2. render 沙箱
16
+ * 子应用在 app mount 开始前生成好的的沙箱。每次子应用切换过后,render 沙箱都会重现初始化。
17
+ *
18
+ * 这么设计的目的是为了保证每个子应用切换回来之后,还能运行在应用 bootstrap 之后的环境下。
19
+ *
20
+ * @param appName
21
+ * @param elementGetter
22
+ * @param scopedCSS
23
+ * @param useLooseSandbox
24
+ * @param excludeAssetFilter
25
+ * @param globalContext
26
+ * @param transformStorage
27
+ */
28
+ export declare function createSandboxContainer(appName: string, elementGetter: () => HTMLElement | ShadowRoot, scopedCSS: boolean, useLooseSandbox?: boolean, excludeAssetFilter?: (url: string) => boolean, globalContext?: typeof window, transformStorage?: boolean): {
29
+ instance: SandBox;
30
+ /**
31
+ * 沙箱被 mount
32
+ * 可能是从 bootstrap 状态进入的 mount
33
+ * 也可能是从 unmount 之后再次唤醒进入 mount
34
+ */
35
+ mount(): Promise<void>;
36
+ /**
37
+ * 恢复 global 状态,使其能回到应用加载之前的状态
38
+ */
39
+ unmount(): Promise<void>;
40
+ };
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createSandboxContainer = createSandboxContainer;
8
+ Object.defineProperty(exports, "css", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _patchers.css;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "getCurrentRunningApp", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _common.getCurrentRunningApp;
18
+ }
19
+ });
20
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
+ var _tslib = require("tslib");
22
+ var _sandbox = _interopRequireDefault(require("./legacy/sandbox"));
23
+ var _patchers = require("./patchers");
24
+ var _proxySandbox = _interopRequireDefault(require("./proxySandbox"));
25
+ var _snapshotSandbox = _interopRequireDefault(require("./snapshotSandbox"));
26
+ var _common = require("./common");
27
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
28
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
29
+ /**
30
+ * 生成应用运行时沙箱
31
+ *
32
+ * 沙箱分两个类型:
33
+ * 1. app 环境沙箱
34
+ * app 环境沙箱是指应用初始化过之后,应用会在什么样的上下文环境运行。每个应用的环境沙箱只会初始化一次,因为子应用只会触发一次 bootstrap 。
35
+ * 子应用在切换时,实际上切换的是 app 环境沙箱。
36
+ * 2. render 沙箱
37
+ * 子应用在 app mount 开始前生成好的的沙箱。每次子应用切换过后,render 沙箱都会重现初始化。
38
+ *
39
+ * 这么设计的目的是为了保证每个子应用切换回来之后,还能运行在应用 bootstrap 之后的环境下。
40
+ *
41
+ * @param appName
42
+ * @param elementGetter
43
+ * @param scopedCSS
44
+ * @param useLooseSandbox
45
+ * @param excludeAssetFilter
46
+ * @param globalContext
47
+ * @param transformStorage
48
+ */
49
+ function createSandboxContainer(appName, elementGetter, scopedCSS, useLooseSandbox, excludeAssetFilter, globalContext, transformStorage) {
50
+ var sandbox;
51
+ if (window.Proxy) {
52
+ sandbox = useLooseSandbox ? new _sandbox.default(appName, globalContext) : new _proxySandbox.default(appName, globalContext, transformStorage);
53
+ } else {
54
+ sandbox = new _snapshotSandbox.default(appName);
55
+ }
56
+ // some side effect could be be invoked while bootstrapping, such as dynamic stylesheet injection with style-loader, especially during the development phase
57
+ var bootstrappingFreers = (0, _patchers.patchAtBootstrapping)(appName, elementGetter, sandbox, scopedCSS, excludeAssetFilter);
58
+ // mounting freers are one-off and should be re-init at every mounting time
59
+ var mountingFreers = [];
60
+ var sideEffectsRebuilders = [];
61
+ return {
62
+ instance: sandbox,
63
+ /**
64
+ * 沙箱被 mount
65
+ * 可能是从 bootstrap 状态进入的 mount
66
+ * 也可能是从 unmount 之后再次唤醒进入 mount
67
+ */
68
+ mount: function mount() {
69
+ return (0, _tslib.__awaiter)(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
70
+ var sideEffectsRebuildersAtBootstrapping, sideEffectsRebuildersAtMounting;
71
+ return _regenerator().w(function (_context) {
72
+ while (1) switch (_context.n) {
73
+ case 0:
74
+ /* ------------------------------------------ 因为有上下文依赖(window),以下代码执行顺序不能变 ------------------------------------------ */
75
+ /* ------------------------------------------ 1. 启动/恢复 沙箱------------------------------------------ */
76
+ sandbox.active();
77
+ sideEffectsRebuildersAtBootstrapping = sideEffectsRebuilders.slice(0, bootstrappingFreers.length);
78
+ sideEffectsRebuildersAtMounting = sideEffectsRebuilders.slice(bootstrappingFreers.length); // must rebuild the side effects which added at bootstrapping firstly to recovery to nature state
79
+ if (sideEffectsRebuildersAtBootstrapping.length) {
80
+ sideEffectsRebuildersAtBootstrapping.forEach(function (rebuild) {
81
+ return rebuild();
82
+ });
83
+ }
84
+ /* ------------------------------------------ 2. 开启全局变量补丁 ------------------------------------------*/
85
+ // render 沙箱启动时开始劫持各类全局监听,尽量不要在应用初始化阶段有 事件监听/定时器 等副作用
86
+ mountingFreers = (0, _patchers.patchAtMounting)(appName, elementGetter, sandbox, scopedCSS, excludeAssetFilter);
87
+ /* ------------------------------------------ 3. 重置一些初始化时的副作用 ------------------------------------------*/
88
+ // 存在 rebuilder 则表明有些副作用需要重建
89
+ if (sideEffectsRebuildersAtMounting.length) {
90
+ sideEffectsRebuildersAtMounting.forEach(function (rebuild) {
91
+ return rebuild();
92
+ });
93
+ }
94
+ // clean up rebuilders
95
+ sideEffectsRebuilders = [];
96
+ case 1:
97
+ return _context.a(2);
98
+ }
99
+ }, _callee);
100
+ }));
101
+ },
102
+ /**
103
+ * 恢复 global 状态,使其能回到应用加载之前的状态
104
+ */
105
+ unmount: function unmount() {
106
+ return (0, _tslib.__awaiter)(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
107
+ return _regenerator().w(function (_context2) {
108
+ while (1) switch (_context2.n) {
109
+ case 0:
110
+ // record the rebuilders of window side effects (event listeners or timers)
111
+ // note that the frees of mounting phase are one-off as it will be re-init at next mounting
112
+ sideEffectsRebuilders = [].concat((0, _toConsumableArray2.default)(bootstrappingFreers), (0, _toConsumableArray2.default)(mountingFreers)).map(function (free) {
113
+ return free();
114
+ });
115
+ sandbox.inactive();
116
+ case 1:
117
+ return _context2.a(2);
118
+ }
119
+ }, _callee2);
120
+ }));
121
+ }
122
+ };
123
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-04-11
4
+ */
5
+ import type { SandBox } from '../../interfaces';
6
+ import { SandBoxType } from '../../interfaces';
7
+ /**
8
+ * 基于 Proxy 实现的沙箱
9
+ * TODO: 为了兼容性 singular 模式下依旧使用该沙箱,等新沙箱稳定之后再切换
10
+ */
11
+ export default class LegacySandbox implements SandBox {
12
+ /** 沙箱期间新增的全局变量 */
13
+ private addedPropsMapInSandbox;
14
+ /** 沙箱期间更新的全局变量 */
15
+ private modifiedPropsOriginalValueMapInSandbox;
16
+ /** 持续记录更新的(新增和修改的)全局变量的 map,用于在任意时刻做 snapshot */
17
+ private currentUpdatedPropsValueMap;
18
+ name: string;
19
+ proxy: WindowProxy;
20
+ globalContext: typeof window;
21
+ type: SandBoxType;
22
+ sandboxRunning: boolean;
23
+ latestSetProp: PropertyKey | null;
24
+ private setWindowProp;
25
+ active(): void;
26
+ inactive(): void;
27
+ constructor(name: string, globalContext?: Window & typeof globalThis);
28
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _interfaces = require("../../interfaces");
13
+ var _common = require("../common");
14
+ function isPropConfigurable(target, prop) {
15
+ var descriptor = Object.getOwnPropertyDescriptor(target, prop);
16
+ return descriptor ? descriptor.configurable : true;
17
+ }
18
+ /**
19
+ * 基于 Proxy 实现的沙箱
20
+ * TODO: 为了兼容性 singular 模式下依旧使用该沙箱,等新沙箱稳定之后再切换
21
+ */
22
+ var LegacySandbox = exports.default = /*#__PURE__*/function () {
23
+ function LegacySandbox(name) {
24
+ var _this = this;
25
+ var globalContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
26
+ (0, _classCallCheck2.default)(this, LegacySandbox);
27
+ /** 沙箱期间新增的全局变量 */
28
+ this.addedPropsMapInSandbox = new Map();
29
+ /** 沙箱期间更新的全局变量 */
30
+ this.modifiedPropsOriginalValueMapInSandbox = new Map();
31
+ /** 持续记录更新的(新增和修改的)全局变量的 map,用于在任意时刻做 snapshot */
32
+ this.currentUpdatedPropsValueMap = new Map();
33
+ this.sandboxRunning = true;
34
+ this.latestSetProp = null;
35
+ this.name = name;
36
+ this.globalContext = globalContext;
37
+ this.type = _interfaces.SandBoxType.LegacyProxy;
38
+ var addedPropsMapInSandbox = this.addedPropsMapInSandbox,
39
+ modifiedPropsOriginalValueMapInSandbox = this.modifiedPropsOriginalValueMapInSandbox,
40
+ currentUpdatedPropsValueMap = this.currentUpdatedPropsValueMap;
41
+ var rawWindow = globalContext;
42
+ var fakeWindow = Object.create(null);
43
+ var setTrap = function setTrap(p, value, originalValue) {
44
+ var sync2Window = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
45
+ if (_this.sandboxRunning) {
46
+ if (!rawWindow.hasOwnProperty(p)) {
47
+ addedPropsMapInSandbox.set(p, value);
48
+ } else if (!modifiedPropsOriginalValueMapInSandbox.has(p)) {
49
+ // 如果当前 window 对象存在该属性,且 record map 中未记录过,则记录该属性初始值
50
+ modifiedPropsOriginalValueMapInSandbox.set(p, originalValue);
51
+ }
52
+ currentUpdatedPropsValueMap.set(p, value);
53
+ if (sync2Window) {
54
+ // 必须重新设置 window 对象保证下次 get 时能拿到已更新的数据
55
+ rawWindow[p] = value;
56
+ }
57
+ _this.latestSetProp = p;
58
+ return true;
59
+ }
60
+ if (process.env.NODE_ENV === 'development') {
61
+ console.warn("[qiankun] Set window.".concat(p.toString(), " while sandbox destroyed or inactive in ").concat(name, "!"));
62
+ }
63
+ // 在 strict-mode 下,Proxy 的 handler.set 返回 false 会抛出 TypeError,在沙箱卸载的情况下应该忽略错误
64
+ return true;
65
+ };
66
+ var proxy = new Proxy(fakeWindow, {
67
+ set: function set(_, p, value) {
68
+ var originalValue = rawWindow[p];
69
+ return setTrap(p, value, originalValue, true);
70
+ },
71
+ get: function get(_, p) {
72
+ // avoid who using window.window or window.self to escape the sandbox environment to touch the really window
73
+ // or use window.top to check if an iframe context
74
+ // see https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L13
75
+ if (p === 'top' || p === 'parent' || p === 'window' || p === 'self') {
76
+ return proxy;
77
+ }
78
+ var value = rawWindow[p];
79
+ return (0, _common.getTargetValue)(rawWindow, value);
80
+ },
81
+ // trap in operator
82
+ // see https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/constants.js#L12
83
+ has: function has(_, p) {
84
+ return p in rawWindow;
85
+ },
86
+ getOwnPropertyDescriptor: function getOwnPropertyDescriptor(_, p) {
87
+ var descriptor = Object.getOwnPropertyDescriptor(rawWindow, p);
88
+ // A property cannot be reported as non-configurable, if it does not exists as an own property of the target object
89
+ if (descriptor && !descriptor.configurable) {
90
+ descriptor.configurable = true;
91
+ }
92
+ return descriptor;
93
+ },
94
+ defineProperty: function defineProperty(_, p, attributes) {
95
+ var originalValue = rawWindow[p];
96
+ var done = Reflect.defineProperty(rawWindow, p, attributes);
97
+ var value = rawWindow[p];
98
+ setTrap(p, value, originalValue, false);
99
+ return done;
100
+ }
101
+ });
102
+ this.proxy = proxy;
103
+ }
104
+ return (0, _createClass2.default)(LegacySandbox, [{
105
+ key: "setWindowProp",
106
+ value: function setWindowProp(prop, value, toDelete) {
107
+ if (value === undefined && toDelete) {
108
+ // eslint-disable-next-line no-param-reassign
109
+ delete this.globalContext[prop];
110
+ } else if (isPropConfigurable(this.globalContext, prop) && (0, _typeof2.default)(prop) !== 'symbol') {
111
+ Object.defineProperty(this.globalContext, prop, {
112
+ writable: true,
113
+ configurable: true
114
+ });
115
+ // eslint-disable-next-line no-param-reassign
116
+ this.globalContext[prop] = value;
117
+ }
118
+ }
119
+ }, {
120
+ key: "active",
121
+ value: function active() {
122
+ var _this2 = this;
123
+ if (!this.sandboxRunning) {
124
+ this.currentUpdatedPropsValueMap.forEach(function (v, p) {
125
+ return _this2.setWindowProp(p, v);
126
+ });
127
+ }
128
+ this.sandboxRunning = true;
129
+ }
130
+ }, {
131
+ key: "inactive",
132
+ value: function inactive() {
133
+ var _this3 = this;
134
+ if (process.env.NODE_ENV === 'development') {
135
+ console.info("[qiankun:sandbox] ".concat(this.name, " modified global properties restore..."), [].concat((0, _toConsumableArray2.default)(this.addedPropsMapInSandbox.keys()), (0, _toConsumableArray2.default)(this.modifiedPropsOriginalValueMapInSandbox.keys())));
136
+ }
137
+ // renderSandboxSnapshot = snapshot(currentUpdatedPropsValueMapForSnapshot);
138
+ // restore global props to initial snapshot
139
+ this.modifiedPropsOriginalValueMapInSandbox.forEach(function (v, p) {
140
+ return _this3.setWindowProp(p, v);
141
+ });
142
+ this.addedPropsMapInSandbox.forEach(function (_, p) {
143
+ return _this3.setWindowProp(p, undefined, true);
144
+ });
145
+ this.sandboxRunning = false;
146
+ }
147
+ }]);
148
+ }();