chayns-api 2.4.6 → 2.4.7-beta.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/dist/cjs/components/ChaynsProvider.js +15 -2
- package/dist/cjs/components/moduleWrapper.js +2 -1
- package/dist/esm/components/ChaynsProvider.js +16 -3
- package/dist/esm/components/moduleWrapper.js +1 -0
- package/dist/types/components/ChaynsProvider.d.ts +1 -0
- package/dist/types/components/moduleWrapper.d.ts +1 -0
- package/package.json +1 -1
|
@@ -39,7 +39,8 @@ const ChaynsProvider = ({
|
|
|
39
39
|
functions,
|
|
40
40
|
customFunctions,
|
|
41
41
|
renderedByServer,
|
|
42
|
-
isModule
|
|
42
|
+
isModule,
|
|
43
|
+
preventOverrideSingleton
|
|
43
44
|
}) => {
|
|
44
45
|
var _customWrapper$curren, _customWrapper$curren2;
|
|
45
46
|
const customWrapper = (0, _react.useRef)(null);
|
|
@@ -65,7 +66,10 @@ const ChaynsProvider = ({
|
|
|
65
66
|
customWrapper.current = new _FrameWrapper.FrameWrapper();
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
_moduleWrapper.
|
|
69
|
+
_moduleWrapper.moduleWrapperList.push(customWrapper.current);
|
|
70
|
+
if (!preventOverrideSingleton || !_moduleWrapper.moduleWrapper.current) {
|
|
71
|
+
_moduleWrapper.moduleWrapper.current = customWrapper.current;
|
|
72
|
+
}
|
|
69
73
|
}
|
|
70
74
|
const [isInitialized, setIsInitialized] = (0, _react.useState)(!!((_customWrapper$curren = customWrapper.current) !== null && _customWrapper$curren !== void 0 && _customWrapper$curren.values));
|
|
71
75
|
(0, _react.useEffect)(() => {
|
|
@@ -94,6 +98,15 @@ const ChaynsProvider = ({
|
|
|
94
98
|
customWrapper.current.emitChange();
|
|
95
99
|
}
|
|
96
100
|
}, [customFunctions, isModule]);
|
|
101
|
+
(0, _react.useEffect)(() => () => {
|
|
102
|
+
const index = _moduleWrapper.moduleWrapperList.indexOf(customWrapper.current);
|
|
103
|
+
if (index > -1) {
|
|
104
|
+
_moduleWrapper.moduleWrapperList.splice(index, 1);
|
|
105
|
+
}
|
|
106
|
+
if (_moduleWrapper.moduleWrapper.current === customWrapper.current) {
|
|
107
|
+
_moduleWrapper.moduleWrapper.current = _moduleWrapper.moduleWrapperList[0];
|
|
108
|
+
}
|
|
109
|
+
}, []);
|
|
97
110
|
return _react.default.createElement(_react.default.Fragment, null, isInitialized && _react.default.createElement(_ChaynsContext.ChaynsContext.Provider, {
|
|
98
111
|
value: customWrapper.current
|
|
99
112
|
}, children), _react.default.createElement(InitialDataProvider, {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.moduleWrapper = void 0;
|
|
6
|
+
exports.moduleWrapperList = exports.moduleWrapper = void 0;
|
|
7
|
+
const moduleWrapperList = exports.moduleWrapperList = [];
|
|
7
8
|
const moduleWrapper = exports.moduleWrapper = {
|
|
8
9
|
current: undefined
|
|
9
10
|
};
|
|
@@ -7,7 +7,7 @@ import { FrameWrapper } from '../wrapper/FrameWrapper';
|
|
|
7
7
|
import { ModuleFederationWrapper } from '../wrapper/ModuleFederationWrapper';
|
|
8
8
|
import { SsrWrapper } from '../wrapper/SsrWrapper';
|
|
9
9
|
import { ChaynsContext } from './ChaynsContext';
|
|
10
|
-
import { moduleWrapper } from './moduleWrapper';
|
|
10
|
+
import { moduleWrapper, moduleWrapperList } from './moduleWrapper';
|
|
11
11
|
const isServer = typeof window === 'undefined';
|
|
12
12
|
const InitialDataProvider = React.memo(_ref => {
|
|
13
13
|
let {
|
|
@@ -33,7 +33,8 @@ const ChaynsProvider = _ref2 => {
|
|
|
33
33
|
functions,
|
|
34
34
|
customFunctions,
|
|
35
35
|
renderedByServer,
|
|
36
|
-
isModule
|
|
36
|
+
isModule,
|
|
37
|
+
preventOverrideSingleton
|
|
37
38
|
} = _ref2;
|
|
38
39
|
const customWrapper = useRef(null);
|
|
39
40
|
if (!customWrapper.current) {
|
|
@@ -58,7 +59,10 @@ const ChaynsProvider = _ref2 => {
|
|
|
58
59
|
customWrapper.current = new FrameWrapper();
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
moduleWrapperList.push(customWrapper.current);
|
|
63
|
+
if (!preventOverrideSingleton || !moduleWrapper.current) {
|
|
64
|
+
moduleWrapper.current = customWrapper.current;
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
const [isInitialized, setIsInitialized] = useState(!!((_customWrapper$curren = customWrapper.current) !== null && _customWrapper$curren !== void 0 && _customWrapper$curren.values));
|
|
64
68
|
useEffect(() => {
|
|
@@ -88,6 +92,15 @@ const ChaynsProvider = _ref2 => {
|
|
|
88
92
|
customWrapper.current.emitChange();
|
|
89
93
|
}
|
|
90
94
|
}, [customFunctions, isModule]);
|
|
95
|
+
useEffect(() => () => {
|
|
96
|
+
const index = moduleWrapperList.indexOf(customWrapper.current);
|
|
97
|
+
if (index > -1) {
|
|
98
|
+
moduleWrapperList.splice(index, 1);
|
|
99
|
+
}
|
|
100
|
+
if (moduleWrapper.current === customWrapper.current) {
|
|
101
|
+
moduleWrapper.current = moduleWrapperList[0];
|
|
102
|
+
}
|
|
103
|
+
}, []);
|
|
91
104
|
return React.createElement(React.Fragment, null, isInitialized && React.createElement(ChaynsContext.Provider, {
|
|
92
105
|
value: customWrapper.current
|
|
93
106
|
}, children), React.createElement(InitialDataProvider, {
|