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

auto-update clusters state in renderer stores

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-07-16 15:31:06 +03:00
parent dec9d92032
commit ab61fd6308
2 changed files with 21 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import path from "path"
import Config from "conf"
import { Options as ConfOptions } from "conf/dist/source/types"
import { app, ipcMain, ipcRenderer, remote } from "electron"
import { action, observable, reaction, toJS, when } from "mobx";
import { action, observable, reaction, runInAction, toJS, when } from "mobx";
import Singleton from "./utils/singleton";
import { getAppVersion } from "./utils/app-version";
import logger from "../main/logger";
@ -101,6 +101,14 @@ export class BaseStore<T = any> extends Singleton {
this.syncDisposers.length = 0;
}
protected applyWithoutSync(callback: () => void) {
this.disableSync();
runInAction(callback);
if (this.params.syncEnabled) {
this.enableSync();
}
}
protected onSync(model: T) {
if (!isEqual(this.toJSON(), model)) {
this.fromStore(model);

View File

@ -1,9 +1,11 @@
import { ipcRenderer } from "electron";
import type { WorkspaceId } from "./workspace-store";
import { action, computed, observable, toJS } from "mobx";
import { v4 as uuid } from "uuid"
import { BaseStore } from "./base-store";
import { Cluster } from "../main/cluster";
import { Cluster, ClusterState } from "../main/cluster";
import migrations from "../migrations/cluster-store"
import logger from "../main/logger";
export interface ClusterStoreModel {
activeCluster?: ClusterId; // last opened cluster
@ -46,6 +48,15 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
migrations: migrations,
});
if (ipcRenderer) {
ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => {
this.applyWithoutSync(() => {
logger.info(`[CLUSTER-STORE]: received cluster(${clusterState.id}) update`, clusterState);
const cluster = this.getById(clusterState.id);
if (cluster) cluster.updateModel(clusterState)
})
})
}
}
@observable activeClusterId: ClusterId;