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

use private static

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-12-01 11:31:03 +02:00
parent 28b0f618be
commit f5bbf72576
2 changed files with 57 additions and 6 deletions

View File

@ -40,13 +40,30 @@ export interface ClusterStoreModel {
export type ClusterId = string;
export interface ClusterModel {
/** Unique id for a cluster */
id: ClusterId;
/** Path to cluster kubeconfig */
kubeConfigPath: string;
/** Workspace id */
workspace?: WorkspaceId;
/** User context in kubeconfig */
contextName?: string;
/** Preferences */
preferences?: ClusterPreferences;
/** Metadata */
metadata?: ClusterMetadata;
/**
* If extension sets ownerRef it has to explicitly mark a cluster as enabled during onActive (or when cluster is saved)
*/
ownerRef?: string;
/** List of accessible namespaces */
accessibleNamespaces?: string[];
/** @deprecated */
@ -89,7 +106,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
@observable removedClusters = observable.map<ClusterId, Cluster>();
@observable clusters = observable.map<ClusterId, Cluster>();
private stateRequestChannel = "cluster:states";
private static stateRequestChannel = "cluster:states";
private constructor() {
super({
@ -112,7 +129,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
};
if (ipcRenderer) {
logger.info("[CLUSTER-STORE] requesting initial state sync");
const clusterStates: clusterStateSync[] = await requestMain(this.stateRequestChannel);
const clusterStates: clusterStateSync[] = await requestMain(ClusterStore.stateRequestChannel);
clusterStates.forEach((clusterState) => {
const cluster = this.getById(clusterState.id);
if (cluster) {
@ -120,7 +137,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
});
} else {
handleRequest(this.stateRequestChannel, (): clusterStateSync[] => {
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
const states: clusterStateSync[] = [];
this.clustersList.forEach((cluster) => {
states.push({

View File

@ -27,11 +27,45 @@ export interface WorkspaceState {
}
export class Workspace implements WorkspaceModel, WorkspaceState {
/**
* Unique id for workspace
*
* @observable
*/
@observable id: WorkspaceId;
/**
* Workspace name
*
* @observable
*/
@observable name: string;
/**
* Workspace description
*
* @observable
*/
@observable description?: string;
/**
* Workspace owner reference
*
* If extension sets ownerRef then it needs to explicitly mark workspace as enabled onActivate (or when workspace is saved)
*
* @observable
*/
@observable ownerRef?: string;
/**
* Is workspace enabled
*
* Workspaces that don't have ownerRef will be enabled by default. Workspaces with ownerRef need to explicitly enable a workspace.
*
* @observable
*/
@observable enabled: boolean;
/**
* Last active cluster id
*
* @observable
*/
@observable lastActiveClusterId?: ClusterId;
constructor(data: WorkspaceModel) {
@ -77,7 +111,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
static readonly defaultId: WorkspaceId = "default";
private stateRequestChannel = "workspace:states";
private static stateRequestChannel = "workspace:states";
private constructor() {
super({
@ -93,7 +127,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
};
if (ipcRenderer) {
logger.info("[WORKSPACE-STORE] requesting initial state sync");
const workspaceStates: workspaceStateSync[] = await requestMain(this.stateRequestChannel);
const workspaceStates: workspaceStateSync[] = await requestMain(WorkspaceStore.stateRequestChannel);
workspaceStates.forEach((workspaceState) => {
const workspace = this.getById(workspaceState.id);
if (workspace) {
@ -101,7 +135,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
}
});
} else {
handleRequest(this.stateRequestChannel, (): workspaceStateSync[] => {
handleRequest(WorkspaceStore.stateRequestChannel, (): workspaceStateSync[] => {
const states: workspaceStateSync[] = [];
this.workspacesList.forEach((workspace) => {
states.push({