mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Add support for using injectionTokens in global overrides
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
3532fc1dab
commit
6ae078c91d
@ -57,7 +57,7 @@ export function getDiForUnitTesting() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const globalOverridePath of global.injectablePaths.main.globalOverridePaths) {
|
for (const globalOverridePath of global.injectablePaths.main.globalOverridePaths) {
|
||||||
const globalOverride = require(globalOverridePath).default as GlobalOverride<unknown, unknown>;
|
const globalOverride = require(globalOverridePath).default as GlobalOverride<unknown, unknown, unknown>;
|
||||||
|
|
||||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export const getDiForUnitTesting = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const globalOverridePath of global.injectablePaths.renderer.globalOverridePaths) {
|
for (const globalOverridePath of global.injectablePaths.renderer.globalOverridePaths) {
|
||||||
const globalOverride = require(globalOverridePath).default as GlobalOverride<unknown, unknown>;
|
const globalOverride = require(globalOverridePath).default as GlobalOverride<unknown, unknown, unknown>;
|
||||||
|
|
||||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,11 +43,12 @@ export const getRequestChannelListenerInjectable = <
|
|||||||
getInjectable({
|
getInjectable({
|
||||||
id: `${info.channel.id}-request-listener-${info.id}`,
|
id: `${info.channel.id}-request-listener-${info.id}`,
|
||||||
|
|
||||||
instantiate: (di) => ({
|
instantiate: (di) =>
|
||||||
|
({
|
||||||
id: `${info.channel.id}-request-listener-${info.id}`,
|
id: `${info.channel.id}-request-listener-${info.id}`,
|
||||||
channel: info.channel,
|
channel: info.channel,
|
||||||
handler: info.getHandler(di),
|
handler: info.getHandler(di),
|
||||||
}),
|
} as RequestChannelListener<Channel>),
|
||||||
|
|
||||||
injectionToken: requestChannelListenerInjectionToken,
|
injectionToken: requestChannelListenerInjectionToken,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,17 +2,30 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import type { Injectable, Instantiate } from "@ogre-tools/injectable";
|
import type { Injectable, InjectionToken, Instantiate } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
export interface GlobalOverride<Instance, Param> {
|
export type GlobalOverride<
|
||||||
injectable: Injectable<Instance, unknown, Param>;
|
InjectionInstance extends InjectionTokenInstance,
|
||||||
overridingInstantiate: Instantiate<Instance, Param>;
|
InjectionTokenInstance,
|
||||||
}
|
InstantiationParam,
|
||||||
|
> = ReturnType<typeof getGlobalOverride<InjectionInstance, InjectionTokenInstance, InstantiationParam>>;
|
||||||
|
|
||||||
export const getGlobalOverride = <Instance, Param>(
|
export function getGlobalOverride<
|
||||||
injectable: Injectable<Instance, unknown, Param>,
|
InjectionInstance extends InjectionTokenInstance,
|
||||||
overridingInstantiate: (typeof injectable)["instantiate"],
|
InjectionTokenInstance,
|
||||||
) => ({
|
InstantiationParam,
|
||||||
|
>(
|
||||||
|
injectable:
|
||||||
|
| InjectionToken<InjectionInstance, InstantiationParam>
|
||||||
|
| Injectable<
|
||||||
|
InjectionInstance,
|
||||||
|
InjectionTokenInstance,
|
||||||
|
InstantiationParam
|
||||||
|
>,
|
||||||
|
overridingInstantiate: Instantiate<InjectionInstance, InstantiationParam>,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
injectable,
|
injectable,
|
||||||
overridingInstantiate,
|
overridingInstantiate,
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user