Skip to content

Commit 5af2376

Browse files
author
HienTM
committed
upgrade core lib
1 parent 666b804 commit 5af2376

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@
3636
"react": "^16.13.1",
3737
"react-dom": "^16.13.1",
3838
"react-router": "^5.1.2"
39+
},
40+
"dependencies": {
41+
"cb-react-micro-frontend-core": "^0.0.3"
3942
}
4043
}

src/microFrontendLoader.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
/* eslint-disable no-underscore-dangle */
2+
import { MF_INFO_KEY } from 'cb-react-micro-frontend-core';
3+
24
const win = (window as unknown) as MicroFrontendGlobal;
3-
const mfInfoKey = '_mfInfo';
45

5-
export const getMicroFrontendInfo = () => win[mfInfoKey];
6+
export const getMicroFrontendInfo = () => win[MF_INFO_KEY];
67

78
export const isLoadedAsMicroFrontend = (name: string) =>
8-
name === win[mfInfoKey]?.name;
9+
name === win[MF_INFO_KEY]?.name;
910

1011
export const removeMicroFrontendInfo = (name?: string) => {
11-
if (!name || win[mfInfoKey]?.name === name) {
12-
win[mfInfoKey] = undefined;
13-
document.cookie = `${mfInfoKey}=; Max-Age=-99999999;`;
12+
if (!name || win[MF_INFO_KEY]?.name === name) {
13+
win[MF_INFO_KEY] = undefined;
14+
document.cookie = `${MF_INFO_KEY}=; Max-Age=-99999999;`;
1415
}
1516
};
1617

1718
export const setMicroFrontendInfo = (name: string, host: string) => {
1819
const info: MicroFrontendInfo = { host, name };
19-
win[mfInfoKey] = info;
20+
win[MF_INFO_KEY] = info;
2021
const expires = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000);
21-
document.cookie = `${mfInfoKey}=${JSON.stringify(
22+
document.cookie = `${MF_INFO_KEY}=${JSON.stringify(
2223
info,
2324
)}; expires=${expires.toUTCString()}; path=/`;
2425
};
2526

2627
interface MicroFrontendGlobal
27-
extends Record<typeof mfInfoKey, MicroFrontendInfo | undefined | null> {}
28+
extends Record<typeof MF_INFO_KEY, MicroFrontendInfo | undefined | null> {}
2829

2930
interface MicroFrontendInfo {
3031
host: string;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ callsites@^3.0.0:
272272
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
273273
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
274274

275+
cb-react-micro-frontend-core@^0.0.3:
276+
version "0.0.3"
277+
resolved "https://registry.yarnpkg.com/cb-react-micro-frontend-core/-/cb-react-micro-frontend-core-0.0.3.tgz#2526434de8389613a0bdc5dd29f4257828c9aed6"
278+
integrity sha512-6aZh4Lg91yEVH+IOX1nohO+On26ekeVDfEXbQteChsTpykyWe+cKPAU3AJvhgHDOMO4qJX0vT0EaVD3pcuhm/g==
279+
275280
chalk@^2.0.0, chalk@^2.1.0:
276281
version "2.4.2"
277282
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"

0 commit comments

Comments
 (0)