From 53b220b2f9ace549a23567c7152a31f40e795303 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Thu, 12 Aug 2021 10:00:55 +0300 Subject: [PATCH 1/3] allow to pass KubeObjectStore.api via constructor Signed-off-by: Jari Kolehmainen --- src/common/k8s-api/kube-object.store.ts | 10 ++++++++-- .../components/+custom-resources/crd-resource.store.ts | 5 +---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/k8s-api/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts index 3215306d930c..80fe46920cfb 100644 --- a/src/common/k8s-api/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -42,7 +42,7 @@ export interface KubeObjectStoreLoadingParams { export abstract class KubeObjectStore extends ItemStore { static defaultContext = observable.box(); // TODO: support multiple cluster contexts - abstract api: KubeApi; + declare public api: KubeApi; public readonly limit?: number; public readonly bufferSize: number = 50000; @observable private loadedNamespaces?: string[]; @@ -55,8 +55,14 @@ export abstract class KubeObjectStore extends ItemStore return when(() => Boolean(this.loadedNamespaces)); } - constructor() { + constructor(api?: KubeApi) { super(); + if (api) this.api = api; + + if (!this.api) { + throw new Error("api is not defined"); + } + makeObservable(this); autoBind(this); this.bindWatchEventsUpdater(); diff --git a/src/renderer/components/+custom-resources/crd-resource.store.ts b/src/renderer/components/+custom-resources/crd-resource.store.ts index f71f8e640016..4eff3d496a47 100644 --- a/src/renderer/components/+custom-resources/crd-resource.store.ts +++ b/src/renderer/components/+custom-resources/crd-resource.store.ts @@ -24,10 +24,7 @@ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObject } from "../../../common/k8s-api/kube-object"; export class CRDResourceStore extends KubeObjectStore { - api: KubeApi; - constructor(api: KubeApi) { - super(); - this.api = api; + super(api); } } From 0925a5e32ea3fca7de295dec7da8154ed57bce9c Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Thu, 12 Aug 2021 10:13:54 +0300 Subject: [PATCH 2/3] cleanup Signed-off-by: Jari Kolehmainen --- src/common/k8s-api/kube-object.store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/k8s-api/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts index 80fe46920cfb..0c1473b4e404 100644 --- a/src/common/k8s-api/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -42,7 +42,7 @@ export interface KubeObjectStoreLoadingParams { export abstract class KubeObjectStore extends ItemStore { static defaultContext = observable.box(); // TODO: support multiple cluster contexts - declare public api: KubeApi; + public api: KubeApi; public readonly limit?: number; public readonly bufferSize: number = 50000; @observable private loadedNamespaces?: string[]; From d5d7ffba9f38ef9c35861856e07f3ac39b32cc76 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Thu, 12 Aug 2021 10:40:57 +0300 Subject: [PATCH 3/3] remove throw for backward compat reasons Signed-off-by: Jari Kolehmainen --- src/common/k8s-api/kube-object.store.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/common/k8s-api/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts index 0c1473b4e404..dc428eb08bd9 100644 --- a/src/common/k8s-api/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -59,10 +59,6 @@ export abstract class KubeObjectStore extends ItemStore super(); if (api) this.api = api; - if (!this.api) { - throw new Error("api is not defined"); - } - makeObservable(this); autoBind(this); this.bindWatchEventsUpdater();