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

clean up / responding to comments

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-05-14 22:29:39 +03:00
parent 456490cca0
commit 97ad405f9f
2 changed files with 16 additions and 15 deletions

View File

@ -22,7 +22,7 @@
import { app, ipcRenderer, remote } from "electron";
import { EventEmitter } from "events";
import { isEqual } from "lodash";
import { action, computed, observable, reaction, when, makeObservable } from "mobx";
import { action, computed, makeObservable, observable, reaction, when } from "mobx";
import path from "path";
import { getHostedCluster } from "../common/cluster-store";
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
@ -126,6 +126,11 @@ export class ExtensionLoader extends Singleton {
await Promise.all([this.whenLoaded, ExtensionsStore.getInstance().whenLoaded]);
// broadcasting extensions between main/renderer processes
reaction(() => this.toJSON(), () => this.broadcastExtensions(), {
fireImmediately: true,
});
// save state on change `extension.isEnabled`
reaction(() => this.storeState, extensionsState => {
ExtensionsStore.getInstance().mergeState(extensionsState);
@ -169,10 +174,6 @@ export class ExtensionLoader extends Singleton {
this.isLoaded = true;
this.loadOnMain();
reaction(() => this.toJSON(), () => {
this.broadcastExtensions(ExtensionLoader.extensionsMainChannel);
});
handleRequest(ExtensionLoader.extensionsMainChannel, () => {
return Array.from(this.toJSON());
});
@ -197,16 +198,20 @@ export class ExtensionLoader extends Singleton {
});
};
reaction(() => this.toJSON(), () => {
this.broadcastExtensions(ExtensionLoader.extensionsRendererChannel);
});
requestMain(ExtensionLoader.extensionsMainChannel).then(extensionListHandler);
subscribeToBroadcast(ExtensionLoader.extensionsMainChannel, (_event, extensions: [LensExtensionId, InstalledExtension][]) => {
extensionListHandler(extensions);
});
}
broadcastExtensions() {
const channel = ipcRenderer
? ExtensionLoader.extensionsRendererChannel
: ExtensionLoader.extensionsMainChannel;
broadcastMessage(channel, Array.from(this.extensions));
}
syncExtensions(extensions: [LensExtensionId, InstalledExtension][]) {
extensions.forEach(([lensExtensionId, extension]) => {
if (!isEqual(this.extensions.get(lensExtensionId), extension)) {
@ -343,8 +348,4 @@ export class ExtensionLoader extends Singleton {
toJSON(): Map<LensExtensionId, InstalledExtension> {
return toJS(this.extensions);
}
broadcastExtensions(channel = ExtensionLoader.extensionsMainChannel) {
broadcastMessage(channel, Array.from(this.extensions));
}
}

View File

@ -87,7 +87,7 @@ export class KubeStatus {
export type IKubeMetaField = keyof IKubeObjectMetadata;
export class KubeObject<Metadata extends IKubeObjectMetadata = IKubeObjectMetadata, Status = any> implements ItemObject {
export class KubeObject<Metadata extends IKubeObjectMetadata = IKubeObjectMetadata, Status = any, Spec = any> implements ItemObject {
static readonly kind: string;
static readonly namespaced: boolean;
@ -95,7 +95,7 @@ export class KubeObject<Metadata extends IKubeObjectMetadata = IKubeObjectMetada
kind: string;
metadata: Metadata;
status?: Status;
spec?: any = {};
spec?: Spec;
static create(data: any) {
return new KubeObject(data);