mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup getDi and registering injectables (#7251)
* Cleanup getDi and registering injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Create more explicit application - Make testing use more production code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix uses of getEnvironmentSpecificLegacyGlobalDiForExtensionApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit tests Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
b5f0960ee1
commit
c67230f322
19 files changed
+110
-133
No files matched your search
@@ -5,19 +5,16 @@
|
||||
import "./components/app.scss";
|
||||
|
||||
import { bootstrap } from "./bootstrap";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
import { runInAction } from "mobx";
|
||||
import { registerInjectables } from "./register-injectables";
|
||||
import type { CreateApplication } from "../common/create-app";
|
||||
import { getDi } from "./getDi";
|
||||
|
||||
interface AppConfig {
|
||||
di: DiContainer;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export function createApp(conf: AppConfig) {
|
||||
const { di, mode } = conf;
|
||||
export const createApplication: CreateApplication = (config) => {
|
||||
const { mode } = config;
|
||||
const di = getDi();
|
||||
|
||||
runInAction(() => {
|
||||
di.register(getInjectable({
|
||||
@@ -25,10 +22,12 @@ export function createApp(conf: AppConfig) {
|
||||
instantiate: () => mode,
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
|
||||
registerInjectables(di);
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
start: () => bootstrap(di),
|
||||
di,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -4,5 +4,17 @@
|
||||
*/
|
||||
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export const getDi = () => createContainer("renderer");
|
||||
export const getDi = () => {
|
||||
const environment = "renderer";
|
||||
const di = createContainer(environment);
|
||||
|
||||
registerMobX(di);
|
||||
registerInjectableReact(di);
|
||||
setLegacyGlobalDiForExtensionApi(di, environment);
|
||||
|
||||
return di;
|
||||
};
|
||||
@@ -4,9 +4,7 @@
|
||||
*/
|
||||
|
||||
import { noop, chunk } from "lodash/fp";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { isInjectable } from "@ogre-tools/injectable";
|
||||
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
||||
@@ -14,47 +12,29 @@ import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id
|
||||
import { runInAction } from "mobx";
|
||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||
import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-state-sync.injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
||||
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
import { applicationInformationFakeInjectable } from "../common/vars/application-information-fake-injectable";
|
||||
import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { getDi } from "./getDi";
|
||||
|
||||
export const getDiForUnitTesting = (
|
||||
opts: { doGeneralOverrides?: boolean } = {},
|
||||
) => {
|
||||
const { doGeneralOverrides = false } = opts;
|
||||
|
||||
const di = createContainer("renderer");
|
||||
|
||||
di.register(getInjectable({
|
||||
id: "node-env",
|
||||
instantiate: () => "production",
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
const di = getDi();
|
||||
|
||||
di.preventSideEffects();
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||
|
||||
const injectables = (
|
||||
global.injectablePaths.renderer.paths
|
||||
runInAction(() => {
|
||||
const injectables = global.injectablePaths.renderer.paths
|
||||
.map(path => require(path))
|
||||
.flatMap(Object.values)
|
||||
.filter(isInjectable)
|
||||
) as Injectable<any, any, any>[];
|
||||
.filter(isInjectable);
|
||||
|
||||
registerMobX(di);
|
||||
registerInjectableReact(di);
|
||||
|
||||
runInAction(() => {
|
||||
di.register(applicationInformationFakeInjectable);
|
||||
|
||||
chunk(100)(injectables).forEach((chunkInjectables) => {
|
||||
di.register(...chunkInjectables);
|
||||
});
|
||||
for (const block of chunk(100)(injectables)) {
|
||||
di.register(...block);
|
||||
}
|
||||
});
|
||||
|
||||
if (doGeneralOverrides) {
|
||||
|
||||
@@ -14,4 +14,5 @@ export * as ReactRouter from "react-router";
|
||||
export * as ReactRouterDom from "react-router-dom";
|
||||
export * as rendererExtensionApi from "../extensions/renderer-api";
|
||||
export * as commonExtensionApi from "../extensions/common-api";
|
||||
export { createApp } from "./create-app";
|
||||
export { createApplication } from "./create-app";
|
||||
export type { CreateApplication, Application, ApplicationConfig } from "../common/create-app";
|
||||
@@ -5,19 +5,10 @@
|
||||
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export function registerInjectables(di: DiContainer) {
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||
|
||||
registerMobX(di);
|
||||
registerInjectableReact(di);
|
||||
|
||||
runInAction(() => {
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
targetModule: module,
|
||||
@@ -29,6 +20,4 @@ export function registerInjectables(di: DiContainer) {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return di;
|
||||
}
|
||||
Reference in new issue
Block a user