mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix cluster state sync
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
731aec1bb8
commit
ec42d10f7b
@ -3,33 +3,41 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { reaction } from "mobx";
|
import { isEqual } from "lodash";
|
||||||
|
import { autorun } from "mobx";
|
||||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||||
|
import type { ClusterId, ClusterState } from "../../../../common/cluster-types";
|
||||||
import { beforeApplicationIsLoadingInjectionToken } from "../../../../main/start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
import { beforeApplicationIsLoadingInjectionToken } from "../../../../main/start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||||
import initClusterStoreInjectable from "../../store/main/init.injectable";
|
import initClusterStoreInjectable from "../../store/main/init.injectable";
|
||||||
import emitClusterStateUpdateInjectable from "./emit-update.injectable";
|
import emitClusterStateUpdateInjectable from "./emit-update.injectable";
|
||||||
|
|
||||||
const setupClusterStateBroadcastingInjectable = getInjectable({
|
const setupClusterStateBroadcastingInjectable = getInjectable({
|
||||||
id: "setup-cluster-state-broadcasting",
|
id: "setup-cluster-state-broadcasting",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => ({
|
||||||
const emitClusterStateUpdate = di.inject(emitClusterStateUpdateInjectable);
|
id: "setup-cluster-state-broadcasting",
|
||||||
const clusterStore = di.inject(clusterStoreInjectable);
|
run: () => {
|
||||||
|
const emitClusterStateUpdate = di.inject(emitClusterStateUpdateInjectable);
|
||||||
|
const clusterStore = di.inject(clusterStoreInjectable);
|
||||||
|
const prevStates = new Map<ClusterId, ClusterState>();
|
||||||
|
|
||||||
|
autorun(() => {
|
||||||
|
for (const cluster of clusterStore.clusters.values()) {
|
||||||
|
const prevState = prevStates.get(cluster.id);
|
||||||
|
const curState = cluster.getState();
|
||||||
|
|
||||||
|
if (!prevState || !isEqual(prevState, curState)) {
|
||||||
|
prevStates.set(cluster.id, curState);
|
||||||
|
|
||||||
return {
|
|
||||||
id: "setup-cluster-state-broadcasting",
|
|
||||||
run: () => {
|
|
||||||
reaction(() => clusterStore.connectedClustersList, () => {
|
|
||||||
for (const cluster of clusterStore.clusters.values()) {
|
|
||||||
emitClusterStateUpdate({
|
emitClusterStateUpdate({
|
||||||
clusterId: cluster.id,
|
clusterId: cluster.id,
|
||||||
state: cluster.getState(),
|
state: cluster.getState(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
},
|
});
|
||||||
runAfter: di.inject(initClusterStoreInjectable),
|
},
|
||||||
};
|
runAfter: di.inject(initClusterStoreInjectable),
|
||||||
},
|
}),
|
||||||
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user