|
1 | 1 | /* eslint-disable no-underscore-dangle */ |
| 2 | +import { MF_INFO_KEY } from 'cb-react-micro-frontend-core'; |
| 3 | + |
2 | 4 | const win = (window as unknown) as MicroFrontendGlobal; |
3 | | -const mfInfoKey = '_mfInfo'; |
4 | 5 |
|
5 | | -export const getMicroFrontendInfo = () => win[mfInfoKey]; |
| 6 | +export const getMicroFrontendInfo = () => win[MF_INFO_KEY]; |
6 | 7 |
|
7 | 8 | export const isLoadedAsMicroFrontend = (name: string) => |
8 | | - name === win[mfInfoKey]?.name; |
| 9 | + name === win[MF_INFO_KEY]?.name; |
9 | 10 |
|
10 | 11 | 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;`; |
14 | 15 | } |
15 | 16 | }; |
16 | 17 |
|
17 | 18 | export const setMicroFrontendInfo = (name: string, host: string) => { |
18 | 19 | const info: MicroFrontendInfo = { host, name }; |
19 | | - win[mfInfoKey] = info; |
| 20 | + win[MF_INFO_KEY] = info; |
20 | 21 | 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( |
22 | 23 | info, |
23 | 24 | )}; expires=${expires.toUTCString()}; path=/`; |
24 | 25 | }; |
25 | 26 |
|
26 | 27 | interface MicroFrontendGlobal |
27 | | - extends Record<typeof mfInfoKey, MicroFrontendInfo | undefined | null> {} |
| 28 | + extends Record<typeof MF_INFO_KEY, MicroFrontendInfo | undefined | null> {} |
28 | 29 |
|
29 | 30 | interface MicroFrontendInfo { |
30 | 31 | host: string; |
|
0 commit comments