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:
parent
d8fdd12a3c
commit
b935dbca78
@ -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.`,
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user