refactor/remove Cluster#frameId

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen committed 2020-11-19 09:12:19 +02:00
1 parent ea2b67f061
commit 43e361727f
4 files changed
+15 -12

No files matched your search

+9 -3
View File
@@ -3,12 +3,14 @@ import { ClusterId, clusterStore } from "./cluster-store";
import { appEventBus } from "./event-bus"
import { ResourceApplier } from "../main/resource-applier";
import { ipcMain } from "electron";
import { observable } from "mobx";
export const clusterActivateHandler = "cluster:activate"
export const clusterSetFrameIdHandler = "cluster:set-frame-id"
export const clusterRefreshHandler = "cluster:refresh"
export const clusterDisconnectHandler = "cluster:disconnect"
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all"
export const clusterFrameMap = observable.map<ClusterId, number>();
if (ipcMain) {
handleRequest(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
@@ -18,10 +20,10 @@ if (ipcMain) {
}
})
handleRequest(clusterSetFrameIdHandler, (event, clusterId: ClusterId, frameId?: number) => {
handleRequest(clusterSetFrameIdHandler, (event, clusterId: ClusterId, frameId: number) => {
const cluster = clusterStore.getById(clusterId);
if (cluster) {
if (frameId) cluster.frameId = frameId; // save cluster's webFrame.routingId to be able to send push-updates
clusterFrameMap.set(cluster.id, frameId)
return cluster.pushState();
}
})
@@ -33,7 +35,11 @@ if (ipcMain) {
handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
appEventBus.emit({name: "cluster", action: "stop"});
return clusterStore.getById(clusterId)?.disconnect();
const cluster = clusterStore.getById(clusterId);
if (cluster) {
cluster.disconnect();
clusterFrameMap.delete(cluster.id)
}
})
handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
+4 -6
View File
@@ -2,8 +2,9 @@
// https://www.electronjs.org/docs/api/ipc-main
// https://www.electronjs.org/docs/api/ipc-renderer
import { ipcMain, ipcRenderer, webContents, remote } from "electron"
import { ipcMain, ipcRenderer, webContents, remote } from "electron";
import logger from "../main/logger";
import { clusterFrameMap } from "./cluster-ipc";
export function handleRequest(channel: string, listener: (...args: any[]) => any) {
ipcMain.handle(channel, listener)
@@ -15,11 +16,8 @@ export async function requestMain(channel: string, ...args: any[]) {
async function getSubFrames(): Promise<number[]> {
const subFrames: number[] = [];
const { clusterStore } = await import("./cluster-store");
clusterStore.clustersList.forEach(cluster => {
if (cluster.frameId) {
subFrames.push(cluster.frameId)
}
clusterFrameMap.forEach((frameId, _) => {
subFrames.push(frameId)
});
return subFrames;
}