mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Revert "Introduce a way to start replacing usages of Singleton base-class with no changes required on use places"
This reverts commit 34a47f5f
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
c92c8f8a11
commit
9f7515db0e
@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2021 OpenLens Authors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
import type { DependencyInjectionContainer } from "@ogre-tools/injectable";
|
|
||||||
|
|
||||||
let kludgeDi: DependencyInjectionContainer;
|
|
||||||
|
|
||||||
export const setDiKludge = (di: DependencyInjectionContainer) => {
|
|
||||||
kludgeDi = di;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDiKludge = () => kludgeDi;
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2021 OpenLens Authors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
import type { Injectable } from "@ogre-tools/injectable";
|
|
||||||
import { getDiKludge } from "../di-kludge";
|
|
||||||
|
|
||||||
type Awaited<TMaybePromise> = TMaybePromise extends PromiseLike<infer TValue>
|
|
||||||
? TValue
|
|
||||||
: TMaybePromise;
|
|
||||||
|
|
||||||
export const getLegacySingleton = <
|
|
||||||
TInjectable extends Injectable<
|
|
||||||
TInstance,
|
|
||||||
TDependencies,
|
|
||||||
TInstantiationParameter
|
|
||||||
>,
|
|
||||||
TInstance,
|
|
||||||
TDependencies extends object,
|
|
||||||
TInstantiationParameter,
|
|
||||||
TMaybePromiseInstance = ReturnType<TInjectable["instantiate"]>,
|
|
||||||
>(
|
|
||||||
injectableKey: TInjectable,
|
|
||||||
) => ({
|
|
||||||
createInstance: (): TMaybePromiseInstance extends PromiseLike<any>
|
|
||||||
? Awaited<TMaybePromiseInstance>
|
|
||||||
: TMaybePromiseInstance => {
|
|
||||||
const di = getDiKludge();
|
|
||||||
|
|
||||||
return di.inject(injectableKey);
|
|
||||||
},
|
|
||||||
|
|
||||||
getInstance: (): TMaybePromiseInstance extends PromiseLike<any>
|
|
||||||
? Awaited<TMaybePromiseInstance>
|
|
||||||
: TMaybePromiseInstance => {
|
|
||||||
const di = getDiKludge();
|
|
||||||
|
|
||||||
return di.inject(injectableKey);
|
|
||||||
},
|
|
||||||
|
|
||||||
resetInstance: () => {
|
|
||||||
const di = getDiKludge();
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
return di.purge(injectableKey);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@ -26,13 +26,10 @@ import {
|
|||||||
createContainer,
|
createContainer,
|
||||||
ConfigurableDependencyInjectionContainer,
|
ConfigurableDependencyInjectionContainer,
|
||||||
} from "@ogre-tools/injectable";
|
} from "@ogre-tools/injectable";
|
||||||
import { setDiKludge } from "../common/di-kludge/di-kludge";
|
|
||||||
|
|
||||||
export const getDiForUnitTesting = () => {
|
export const getDiForUnitTesting = () => {
|
||||||
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
||||||
|
|
||||||
setDiKludge(di);
|
|
||||||
|
|
||||||
getInjectableFilePaths()
|
getInjectableFilePaths()
|
||||||
.map(key => {
|
.map(key => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
|||||||
@ -20,19 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createContainer } from "@ogre-tools/injectable";
|
import { createContainer } from "@ogre-tools/injectable";
|
||||||
import { setDiKludge } from "../common/di-kludge/di-kludge";
|
|
||||||
|
|
||||||
export const getDi = () => {
|
export const getDi = () =>
|
||||||
const di = createContainer(
|
createContainer(
|
||||||
getRequireContextForMainCode,
|
getRequireContextForMainCode,
|
||||||
getRequireContextForCommonExtensionCode,
|
getRequireContextForCommonExtensionCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
setDiKludge(di);
|
|
||||||
|
|
||||||
return di;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRequireContextForMainCode = () =>
|
const getRequireContextForMainCode = () =>
|
||||||
require.context("./", true, /\.injectable\.(ts|tsx)$/);
|
require.context("./", true, /\.injectable\.(ts|tsx)$/);
|
||||||
|
|
||||||
|
|||||||
@ -26,13 +26,10 @@ import {
|
|||||||
createContainer,
|
createContainer,
|
||||||
ConfigurableDependencyInjectionContainer,
|
ConfigurableDependencyInjectionContainer,
|
||||||
} from "@ogre-tools/injectable";
|
} from "@ogre-tools/injectable";
|
||||||
import { setDiKludge } from "../common/di-kludge/di-kludge";
|
|
||||||
|
|
||||||
export const getDiForUnitTesting = () => {
|
export const getDiForUnitTesting = () => {
|
||||||
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
||||||
|
|
||||||
setDiKludge(di);
|
|
||||||
|
|
||||||
getInjectableFilePaths()
|
getInjectableFilePaths()
|
||||||
.map(key => {
|
.map(key => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
|||||||
@ -20,19 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createContainer } from "@ogre-tools/injectable";
|
import { createContainer } from "@ogre-tools/injectable";
|
||||||
import { setDiKludge } from "../../common/di-kludge/di-kludge";
|
|
||||||
|
|
||||||
export const getDi = () => {
|
export const getDi = () =>
|
||||||
const di = createContainer(
|
createContainer(
|
||||||
getRequireContextForRendererCode,
|
getRequireContextForRendererCode,
|
||||||
getRequireContextForCommonExtensionCode,
|
getRequireContextForCommonExtensionCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
setDiKludge(di);
|
|
||||||
|
|
||||||
return di;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRequireContextForRendererCode = () =>
|
const getRequireContextForRendererCode = () =>
|
||||||
require.context("../", true, /\.injectable\.(ts|tsx)$/);
|
require.context("../", true, /\.injectable\.(ts|tsx)$/);
|
||||||
|
|
||||||
|
|||||||
@ -26,13 +26,10 @@ import {
|
|||||||
createContainer,
|
createContainer,
|
||||||
ConfigurableDependencyInjectionContainer,
|
ConfigurableDependencyInjectionContainer,
|
||||||
} from "@ogre-tools/injectable";
|
} from "@ogre-tools/injectable";
|
||||||
import { setDiKludge } from "../../common/di-kludge/di-kludge";
|
|
||||||
|
|
||||||
export const getDiForUnitTesting = () => {
|
export const getDiForUnitTesting = () => {
|
||||||
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
||||||
|
|
||||||
setDiKludge(di);
|
|
||||||
|
|
||||||
getInjectableFilePaths()
|
getInjectableFilePaths()
|
||||||
.map(key => {
|
.map(key => {
|
||||||
const injectable = require(key).default;
|
const injectable = require(key).default;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user