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

fix upgrade-chart/store.ts and dock-tab.store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-04-12 14:38:33 -04:00
parent 9f9371acd4
commit c849ab432b
2 changed files with 10 additions and 23 deletions

View File

@ -16,32 +16,21 @@ export interface DockTabStoreOptions {
export type DockTabStorageState<T> = Record<TabId, T>; export type DockTabStorageState<T> = Record<TabId, T>;
interface DockTabStoreDependencies { export interface DockTabStoreDependencies {
createStorage: CreateStorage; createStorage: CreateStorage;
} }
export class DockTabStore<T> { export class DockTabStore<T> {
protected storage?: StorageLayer<DockTabStorageState<T>>; protected readonly storage?: StorageLayer<DockTabStorageState<T>>;
private data = observable.map<TabId, T>(); private readonly data = observable.map<TabId, T>();
constructor(protected dependencies: DockTabStoreDependencies, protected options: DockTabStoreOptions) { constructor(protected readonly dependencies: DockTabStoreDependencies, protected readonly options: DockTabStoreOptions) {
autoBind(this); autoBind(this);
this.options.autoInit ??= true;
this.options = { const { storageKey, autoInit } = this.options;
autoInit: true,
...this.options,
};
if (this.options.autoInit) { if (autoInit && storageKey) {
this.init();
}
}
protected init() {
const { storageKey } = this.options;
// auto-save to local-storage
if (storageKey) {
const storage = this.storage = this.dependencies.createStorage(storageKey, {}); const storage = this.storage = this.dependencies.createStorage(storageKey, {});
storage.whenReady.then(() => { storage.whenReady.then(() => {

View File

@ -5,10 +5,9 @@
import { action, computed, makeObservable } from "mobx"; import { action, computed, makeObservable } from "mobx";
import type { TabId } from "../dock/store"; import type { TabId } from "../dock/store";
import type { DockTabStorageState } from "../dock-tab-store/dock-tab.store"; import type { DockTabStoreDependencies } from "../dock-tab-store/dock-tab.store";
import { DockTabStore } from "../dock-tab-store/dock-tab.store"; import { DockTabStore } from "../dock-tab-store/dock-tab.store";
import { getReleaseValues } from "../../../../common/k8s-api/endpoints/helm-releases.api"; import { getReleaseValues } from "../../../../common/k8s-api/endpoints/helm-releases.api";
import type { StorageHelper } from "../../../utils";
import assert from "assert"; import assert from "assert";
export interface IChartUpgradeData { export interface IChartUpgradeData {
@ -16,9 +15,8 @@ export interface IChartUpgradeData {
releaseNamespace: string; releaseNamespace: string;
} }
interface Dependencies { export interface UpgradeChartTabStoreDependencies extends DockTabStoreDependencies {
valuesStore: DockTabStore<string>; valuesStore: DockTabStore<string>;
createStorage: <T>(storageKey: string, options: DockTabStorageState<T>) => StorageHelper<DockTabStorageState<T>>;
} }
export class UpgradeChartTabStore extends DockTabStore<IChartUpgradeData> { export class UpgradeChartTabStore extends DockTabStore<IChartUpgradeData> {
@ -30,7 +28,7 @@ export class UpgradeChartTabStore extends DockTabStore<IChartUpgradeData> {
return this.dependencies.valuesStore; return this.dependencies.valuesStore;
} }
constructor(protected dependencies : Dependencies) { constructor(protected readonly dependencies: UpgradeChartTabStoreDependencies) {
super(dependencies, { super(dependencies, {
storageKey: "chart_releases", storageKey: "chart_releases",
}); });