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.
@@ -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.moduleWrapper.current = customWrapper.current;
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
- moduleWrapper.current = customWrapper.current;
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, {
@@ -1,3 +1,4 @@
1
+ export const moduleWrapperList = [];
1
2
  export const moduleWrapper = {
2
3
  current: undefined
3
4
  };
@@ -7,6 +7,7 @@ type ChaynsProviderProps = {
7
7
  renderedByServer?: boolean;
8
8
  isModule?: boolean;
9
9
  children?: ReactNode;
10
+ preventOverrideSingleton?: boolean;
10
11
  };
11
12
  declare const ChaynsProvider: React.FC<ChaynsProviderProps>;
12
13
  export default ChaynsProvider;
@@ -1,4 +1,5 @@
1
1
  import { IChaynsReact } from '../types/IChaynsReact';
2
+ export declare const moduleWrapperList: IChaynsReact[];
2
3
  export declare const moduleWrapper: {
3
4
  current: IChaynsReact;
4
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.4.6",
3
+ "version": "2.4.7-beta.0",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",