mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import type { Injectable, TentativeTuple } from "@ogre-tools/injectable";
|
|
|
|
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
|
|
|
type FactoryType = <
|
|
TInjectable extends Injectable<unknown, TInstance, TInstantiationParameter>,
|
|
TInstantiationParameter,
|
|
TInstance extends (...args: unknown[]) => any,
|
|
TFunction extends (...args: unknown[]) => any = Awaited<
|
|
ReturnType<TInjectable["instantiate"]>
|
|
>,
|
|
>(
|
|
injectableKey: TInjectable,
|
|
...instantiationParameter: TentativeTuple<TInstantiationParameter>
|
|
) => (...args: Parameters<TFunction>) => ReturnType<TFunction>;
|
|
|
|
export const asLegacyGlobalFunctionForExtensionApi: FactoryType =
|
|
(injectableKey, ...instantiationParameter) =>
|
|
(...args) => {
|
|
const injected = getLegacyGlobalDiForExtensionApi().inject(
|
|
injectableKey,
|
|
...instantiationParameter,
|
|
);
|
|
|
|
return injected(...args);
|
|
};
|