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