1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Introduce a legacy-helper to make gradual refactoring of inheritors of Singleton easier

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-03-22 15:01:19 +02:00 committed by Janne Savolainen
parent d8fdd12a3c
commit b935dbca78
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { Injectable } from "@ogre-tools/injectable";
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
import loggerInjectable from "../../common/logger.injectable";
export const asLegacyGlobalSingletonForExtensionApi = <
Instance,
InstantiationParameter = void,
>(
injectable: Injectable<Instance, unknown, InstantiationParameter>,
instantiationParameter?: InstantiationParameter,
) => {
const instance = asLegacyGlobalForExtensionApi(
injectable,
instantiationParameter,
);
return {
createInstance: () => instance,
getInstance: () => instance,
resetInstance: () => {
const di = getLegacyGlobalDiForExtensionApi();
const logger = di.inject(loggerInjectable);
logger.warn(
`resetInstance() for a legacy global singleton of "${injectable.id}" does nothing.`,
);
},
};
};