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:
parent
9f25212f45
commit
b8fd1299ee
@ -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",
|
||||
});
|
||||
@ -5,6 +5,7 @@
|
||||
import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting";
|
||||
import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting";
|
||||
import { overrideIpcBridge } from "./override-ipc-bridge";
|
||||
import { setupableInjectionToken } from "../common/setupable-injection-token/setupable-injection-token";
|
||||
|
||||
export const getDisForUnitTesting = ({ doGeneralOverrides } = { doGeneralOverrides: false }) => {
|
||||
const rendererDi = getRendererDi({ doGeneralOverrides });
|
||||
@ -15,6 +16,17 @@ export const getDisForUnitTesting = ({ doGeneralOverrides } = { doGeneralOverrid
|
||||
return {
|
||||
rendererDi,
|
||||
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,
|
||||
]);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user