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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ export const getDiForUnitTesting = () => {
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -43,11 +43,12 @@ export const getRequestChannelListenerInjectable = <
|
||||
getInjectable({
|
||||
id: `${info.channel.id}-request-listener-${info.id}`,
|
||||
|
||||
instantiate: (di) => ({
|
||||
id: `${info.channel.id}-request-listener-${info.id}`,
|
||||
channel: info.channel,
|
||||
handler: info.getHandler(di),
|
||||
}),
|
||||
instantiate: (di) =>
|
||||
({
|
||||
id: `${info.channel.id}-request-listener-${info.id}`,
|
||||
channel: info.channel,
|
||||
handler: info.getHandler(di),
|
||||
} as RequestChannelListener<Channel>),
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
@ -2,17 +2,30 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* 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> {
|
||||
injectable: Injectable<Instance, unknown, Param>;
|
||||
overridingInstantiate: Instantiate<Instance, Param>;
|
||||
export type GlobalOverride<
|
||||
InjectionInstance extends InjectionTokenInstance,
|
||||
InjectionTokenInstance,
|
||||
InstantiationParam,
|
||||
> = ReturnType<typeof getGlobalOverride<InjectionInstance, InjectionTokenInstance, InstantiationParam>>;
|
||||
|
||||
export function getGlobalOverride<
|
||||
InjectionInstance extends InjectionTokenInstance,
|
||||
InjectionTokenInstance,
|
||||
InstantiationParam,
|
||||
>(
|
||||
injectable:
|
||||
| InjectionToken<InjectionInstance, InstantiationParam>
|
||||
| Injectable<
|
||||
InjectionInstance,
|
||||
InjectionTokenInstance,
|
||||
InstantiationParam
|
||||
>,
|
||||
overridingInstantiate: Instantiate<InjectionInstance, InstantiationParam>,
|
||||
) {
|
||||
return {
|
||||
injectable,
|
||||
overridingInstantiate,
|
||||
};
|
||||
}
|
||||
|
||||
export const getGlobalOverride = <Instance, Param>(
|
||||
injectable: Injectable<Instance, unknown, Param>,
|
||||
overridingInstantiate: (typeof injectable)["instantiate"],
|
||||
) => ({
|
||||
injectable,
|
||||
overridingInstantiate,
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user