Remove more usages of Singleton

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-12-06 09:18:58 -05:00
1 parent 257082e699
commit 9fee31a872
18 files changed
+152 -129

No files matched your search

@@ -5,13 +5,14 @@
import type { CatalogEntityActionContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus, CatalogCategorySpec } from "../catalog";
import { CatalogEntity, CatalogCategory, categoryVersion } from "../catalog/catalog-entity";
import { ClusterStore } from "../cluster-store/cluster-store";
import { broadcastMessage } from "../ipc";
import { app } from "electron";
import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/catalog-entity";
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
import { requestClusterActivation, requestClusterDisconnection } from "../../renderer/ipc";
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
import getClusterByIdInjectable from "../cluster-store/get-by-id.injectable";
export interface KubernetesClusterPrometheusMetrics {
address?: {
@@ -63,6 +64,8 @@ export function isKubernetesCluster(item: unknown): item is KubernetesCluster {
return item instanceof KubernetesCluster;
}
const getClusterById = asLegacyGlobalFunctionForExtensionApi(getClusterByIdInjectable);
export class KubernetesCluster<
Metadata extends KubernetesClusterMetadata = KubernetesClusterMetadata,
Status extends KubernetesClusterStatus = KubernetesClusterStatus,
@@ -76,7 +79,7 @@ export class KubernetesCluster<
async connect(): Promise<void> {
if (app) {
await ClusterStore.getInstance().getById(this.getId())?.activate();
await getClusterById(this.getId())?.activate();
} else {
await requestClusterActivation(this.getId(), false);
}
@@ -84,7 +87,7 @@ export class KubernetesCluster<
async disconnect(): Promise<void> {
if (app) {
ClusterStore.getInstance().getById(this.getId())?.disconnect();
getClusterById(this.getId())?.disconnect();
} else {
await requestClusterDisconnection(this.getId(), false);
}
+2 -1
View File
@@ -34,12 +34,13 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
// NOTE: this is safe because `onContextMenuOpen` is only supposed to be called in the renderer
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer);
const productName = di.inject(productNameInjectable);
const weblinkStore = di.inject(weblinkStoreInjectable);
if (this.metadata.source === "local") {
context.menuItems.push({
title: "Delete",
icon: "delete",
onClick: async () => di.inject(weblinkStoreInjectable).removeById(this.getId()),
onClick: async () => weblinkStore.removeById(this.getId()),
confirm: {
message: `Remove Web Link "${this.getName()}" from ${productName}?`,
},
@@ -7,11 +7,6 @@ import clusterStoreInjectable from "./cluster-store.injectable";
import type { Cluster } from "../cluster/cluster";
import type { ClusterStore } from "./cluster-store";
export default getGlobalOverride(
clusterStoreInjectable,
() =>
({
provideInitialFromMain: () => {},
getById: (id) => (void id, {}) as Cluster,
} as ClusterStore),
);
export default getGlobalOverride(clusterStoreInjectable, () => ({
getById: () => ({}) as Cluster,
} as Partial<ClusterStore> as ClusterStore));
-11
View File
@@ -10,11 +10,9 @@ import { BaseStore } from "../base-store";
import { Cluster } from "../cluster/cluster";
import migrations from "../../migrations/cluster-store";
import logger from "../../main/logger";
import { ipcMainHandle } from "../ipc";
import { disposer, toJS } from "../utils";
import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types";
import { requestInitialClusterStates } from "../../renderer/ipc";
import { clusterStates } from "../ipc/cluster";
import type { CreateCluster } from "../cluster/create-cluster-injection-token";
import type { ReadClusterConfigSync } from "./read-cluster-config.injectable";
import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable";
@@ -58,15 +56,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
}
provideInitialFromMain() {
ipcMainHandle(clusterStates, () => (
this.clustersList.map(cluster => ({
id: cluster.id,
state: cluster.getState(),
}))
));
}
protected pushStateToViewsAutomatically() {
if (ipcMain) {
this.disposer.push(