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

Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-06-08 09:18:56 -04:00
parent bbcdd541ef
commit 469f54b594
6 changed files with 27 additions and 12 deletions

View File

@ -7,7 +7,7 @@ import type { ClusterContext } from "./cluster-context";
import { action, computed, makeObservable, observable, reaction, when } from "mobx"; import { action, computed, makeObservable, observable, reaction, when } from "mobx";
import type { Disposer } from "../utils"; import type { Disposer } from "../utils";
import { autoBind, includes, isRequestError, noop, rejectPromiseBy } from "../utils"; import { waitUntilDefined, autoBind, includes, isRequestError, noop, rejectPromiseBy } from "../utils";
import type { KubeJsonApiDataFor, KubeObject } from "./kube-object"; import type { KubeJsonApiDataFor, KubeObject } from "./kube-object";
import { KubeStatus } from "./kube-object"; import { KubeStatus } from "./kube-object";
import type { IKubeWatchEvent } from "./kube-watch-event"; import type { IKubeWatchEvent } from "./kube-watch-event";
@ -114,7 +114,7 @@ export abstract class KubeObjectStore<
this.bindWatchEventsUpdater(); this.bindWatchEventsUpdater();
} }
get context(): ClusterContext { get context(): ClusterContext | undefined {
return KubeObjectStore.defaultContext.get(); return KubeObjectStore.defaultContext.get();
} }
@ -259,8 +259,9 @@ export abstract class KubeObjectStore<
@action @action
async loadAll({ namespaces, merge = true, reqInit, onLoadFailure }: KubeObjectStoreLoadAllParams = {}): Promise<undefined | K[]> { async loadAll({ namespaces, merge = true, reqInit, onLoadFailure }: KubeObjectStoreLoadAllParams = {}): Promise<undefined | K[]> {
await this.contextReady; const context = await waitUntilDefined(() => this.context);
namespaces ??= this.context.contextNamespaces;
namespaces ??= context.contextNamespaces;
this.isLoading = true; this.isLoading = true;
try { try {
@ -427,11 +428,17 @@ export abstract class KubeObjectStore<
subscribe({ onLoadFailure, abortController = new AbortController() }: KubeObjectStoreSubscribeParams = {}): Disposer { subscribe({ onLoadFailure, abortController = new AbortController() }: KubeObjectStoreSubscribeParams = {}): Disposer {
if (this.api.isNamespaced) { if (this.api.isNamespaced) {
Promise.race([rejectPromiseBy(abortController.signal), Promise.all([this.contextReady, this.namespacesReady])]) Promise.race([
.then(() => { rejectPromiseBy(abortController.signal),
Promise.all([
waitUntilDefined(() => this.context),
this.namespacesReady,
] as const),
])
.then(([context]) => {
assert(this.loadedNamespaces); assert(this.loadedNamespaces);
if (this.context.cluster?.isGlobalWatchEnabled && this.loadedNamespaces.length === 0) { if (context.cluster?.isGlobalWatchEnabled && this.loadedNamespaces.length === 0) {
return this.watchNamespace("", abortController, { onLoadFailure }); return this.watchNamespace("", abortController, { onLoadFailure });
} }

View File

@ -11,7 +11,7 @@ import "abort-controller/polyfill";
* Useful for `Promise.race()` applications. * Useful for `Promise.race()` applications.
* @param signal The AbortController's signal to reject with * @param signal The AbortController's signal to reject with
*/ */
export function rejectPromiseBy(signal: AbortSignal): Promise<void> { export function rejectPromiseBy(signal: AbortSignal): Promise<never> {
return new Promise((_, reject) => { return new Promise((_, reject) => {
signal.addEventListener("abort", reject); signal.addEventListener("abort", reject);
}); });

View File

@ -25,7 +25,11 @@ const createSyncBoxInjectable = getInjectable({
return { return {
id, id,
value: computed(() => state.get()), /**
* SAFETY: we unconditionally set the value above and only allow `TData` with the `.set`
* function so this is always `TData`.
*/
value: computed(() => state.get() as TData),
set: (value) => { set: (value) => {
state.set(value); state.set(value);

View File

@ -17,6 +17,10 @@ const currentClusterFrameInjectable = getInjectable({
return computed(() => { return computed(() => {
const clusterId = currentClusterFrameState.get(); const clusterId = currentClusterFrameState.get();
if (!clusterId) {
return undefined;
}
return clusterFrames.get(clusterId); return clusterFrames.get(clusterId);
}); });
}, },

View File

@ -114,7 +114,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
* if user has given static list of namespaces let's not start watches * if user has given static list of namespaces let's not start watches
* because watch adds stuff that's not wanted or will just fail * because watch adds stuff that's not wanted or will just fail
*/ */
if (this.context.cluster.accessibleNamespaces.length > 0) { if ((this.context?.cluster.accessibleNamespaces.length ?? 0) > 0) {
return noop; return noop;
} }

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token"; import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
import syncBoxInitialValueChannelInjectable from "../../../common/utils/sync-box/sync-box-initial-value-channel.injectable"; import syncBoxInitialValueChannelInjectable from "../../../common/utils/sync-box/sync-box-initial-value-channel.injectable";
import syncBoxStateInjectable from "../../../common/utils/sync-box/sync-box-state.injectable"; import createSyncBoxStateInjectable from "../../../common/utils/sync-box/sync-box-state.injectable";
import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token"; import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token";
const provideInitialValuesForSyncBoxesInjectable = getInjectable({ const provideInitialValuesForSyncBoxesInjectable = getInjectable({
@ -14,7 +14,7 @@ const provideInitialValuesForSyncBoxesInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectionToken); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
const syncBoxInitialValueChannel = di.inject(syncBoxInitialValueChannelInjectable); const syncBoxInitialValueChannel = di.inject(syncBoxInitialValueChannelInjectable);
const setSyncBoxState = (id: string, state: any) => di.inject(syncBoxStateInjectable, id).set(state); const setSyncBoxState = (id: string, state: any) => di.inject(createSyncBoxStateInjectable, id).set(state);
return { return {
run: async () => { run: async () => {