1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api.ts
Janne Savolainen c441ad1496
Adapt to typing changes in injectable
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-05-11 08:18:33 +03:00

47 lines
1.2 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { Inject } from "@ogre-tools/injectable";
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
export const asLegacyGlobalForExtensionApi = ((
injectable,
instantiationParameter,
) =>
new Proxy(
{},
{
apply(target: any, thisArg, argArray) {
const fn = getLegacyGlobalDiForExtensionApi().inject(
injectable,
instantiationParameter,
) as unknown as (...args: any[]) => any;
return fn(...argArray);
},
get(target, propertyName) {
if (propertyName === "$$typeof") {
return undefined;
}
const instance: any = getLegacyGlobalDiForExtensionApi().inject(
injectable,
instantiationParameter,
);
const propertyValue = instance[propertyName] ?? target[propertyName];
if (typeof propertyValue === "function") {
return function (...args: any[]) {
return propertyValue.apply(instance, args);
};
}
return propertyValue;
},
},
)) as Inject;