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

Introduce injection token as competition for injectable setup to have better control of timing of different setups

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-03-29 10:56:26 +03:00
parent 9f25212f45
commit b8fd1299ee
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
export interface Setupable {
doSetup: () => Promise<void> | void;
}
export const setupableInjectionToken = getInjectionToken<Setupable>({
id: "setupable-injection-token",
});

View File

@ -5,6 +5,7 @@
import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting"; import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting";
import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting"; import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting";
import { overrideIpcBridge } from "./override-ipc-bridge"; import { overrideIpcBridge } from "./override-ipc-bridge";
import { setupableInjectionToken } from "../common/setupable-injection-token/setupable-injection-token";
export const getDisForUnitTesting = ({ doGeneralOverrides } = { doGeneralOverrides: false }) => { export const getDisForUnitTesting = ({ doGeneralOverrides } = { doGeneralOverrides: false }) => {
const rendererDi = getRendererDi({ doGeneralOverrides }); const rendererDi = getRendererDi({ doGeneralOverrides });
@ -15,6 +16,17 @@ export const getDisForUnitTesting = ({ doGeneralOverrides } = { doGeneralOverrid
return { return {
rendererDi, rendererDi,
mainDi, mainDi,
runSetups: () => Promise.all([rendererDi.runSetups(), mainDi.runSetups()]), runSetups: () => {
const setupPromises = [
...rendererDi.injectMany(setupableInjectionToken),
...mainDi.injectMany(setupableInjectionToken),
].map(setupable => setupable.doSetup());
return Promise.all([
rendererDi.runSetups(),
mainDi.runSetups(),
...setupPromises,
]);
},
}; };
}; };