🐛 init global name map for app instance (#1860)
This commit is contained in:
parent
eebaf5033f
commit
aa6d4afc27
18
src/utils.ts
18
src/utils.ts
|
|
@ -111,22 +111,18 @@ export function getWrapperId(name: string) {
|
|||
|
||||
export const nativeGlobal = new Function('return this')();
|
||||
|
||||
Object.defineProperty(nativeGlobal, '__app_instance_name_map__', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: {},
|
||||
});
|
||||
/**
|
||||
* get app instance name with the auto-increment approach
|
||||
* @param appName
|
||||
*/
|
||||
export const getAppInstanceName = (appName: string): string => {
|
||||
if (typeof nativeGlobal.__app_instance_name_map__?.[appName] === undefined) {
|
||||
const prevAppsCount = nativeGlobal.__app_instance_name_map__ || {};
|
||||
Object.defineProperty(nativeGlobal, '__app_instance_name_map__', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: {
|
||||
...prevAppsCount,
|
||||
[appName]: 0,
|
||||
},
|
||||
});
|
||||
|
||||
if (!(appName in nativeGlobal.__app_instance_name_map__)) {
|
||||
nativeGlobal.__app_instance_name_map__[appName] = 0;
|
||||
return appName;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user