From 0dfd03e6dfe0975ad49d388db3daa79267a0f82d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 16:17:44 -0400 Subject: [PATCH] Bump mobx from 6.5.0 to 6.6.0 (#5570) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Malton --- package.json | 2 +- src/common/k8s-api/kube-object.store.ts | 21 ++++++++++++------- src/common/utils/reject-promise.ts | 2 +- .../sync-box/create-sync-box.injectable.ts | 5 +++-- .../sync-box/sync-box-injection-token.ts | 17 +++------------ .../current-cluster-frame.injectable.ts | 4 ++++ src/renderer/components/+namespaces/store.ts | 2 +- ...nitial-values-for-sync-boxes.injectable.ts | 4 ++-- yarn.lock | 8 +++---- 9 files changed, 33 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 0cf83db2cf..a4c913e426 100644 --- a/package.json +++ b/package.json @@ -242,7 +242,7 @@ "mac-ca": "^1.0.6", "marked": "^4.0.17", "md5-file": "^5.0.0", - "mobx": "^6.5.0", + "mobx": "^6.6.0", "mobx-observable-history": "^2.0.3", "mobx-react": "^7.5.0", "mobx-utils": "^6.0.4", diff --git a/src/common/k8s-api/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts index ca4e1d9000..855e1a1315 100644 --- a/src/common/k8s-api/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -7,7 +7,7 @@ import type { ClusterContext } from "./cluster-context"; import { action, computed, makeObservable, observable, reaction, when } from "mobx"; 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 { KubeStatus } from "./kube-object"; import type { IKubeWatchEvent } from "./kube-watch-event"; @@ -114,7 +114,7 @@ export abstract class KubeObjectStore< this.bindWatchEventsUpdater(); } - get context(): ClusterContext { + get context(): ClusterContext | undefined { return KubeObjectStore.defaultContext.get(); } @@ -259,8 +259,9 @@ export abstract class KubeObjectStore< @action async loadAll({ namespaces, merge = true, reqInit, onLoadFailure }: KubeObjectStoreLoadAllParams = {}): Promise { - await this.contextReady; - namespaces ??= this.context.contextNamespaces; + const context = await waitUntilDefined(() => this.context); + + namespaces ??= context.contextNamespaces; this.isLoading = true; try { @@ -427,11 +428,17 @@ export abstract class KubeObjectStore< subscribe({ onLoadFailure, abortController = new AbortController() }: KubeObjectStoreSubscribeParams = {}): Disposer { if (this.api.isNamespaced) { - Promise.race([rejectPromiseBy(abortController.signal), Promise.all([this.contextReady, this.namespacesReady])]) - .then(() => { + Promise.race([ + rejectPromiseBy(abortController.signal), + Promise.all([ + waitUntilDefined(() => this.context), + this.namespacesReady, + ] as const), + ]) + .then(([context]) => { 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 }); } diff --git a/src/common/utils/reject-promise.ts b/src/common/utils/reject-promise.ts index d8a802b51a..8212bacd3f 100644 --- a/src/common/utils/reject-promise.ts +++ b/src/common/utils/reject-promise.ts @@ -11,7 +11,7 @@ import type { AbortSignal } from "abort-controller"; * Useful for `Promise.race()` applications. * @param signal The AbortController's signal to reject with */ -export function rejectPromiseBy(signal: AbortSignal): Promise { +export function rejectPromiseBy(signal: AbortSignal): Promise { return new Promise((_, reject) => { signal.addEventListener("abort", reject); }); diff --git a/src/common/utils/sync-box/create-sync-box.injectable.ts b/src/common/utils/sync-box/create-sync-box.injectable.ts index 2cf3de6a69..1328106e24 100644 --- a/src/common/utils/sync-box/create-sync-box.injectable.ts +++ b/src/common/utils/sync-box/create-sync-box.injectable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { IObservableValue } from "mobx"; import { computed } from "mobx"; import syncBoxChannelInjectable from "./sync-box-channel.injectable"; import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token"; @@ -17,8 +18,8 @@ const createSyncBoxInjectable = getInjectable({ const messageToChannel = di.inject(messageToChannelInjectionToken); const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id); - return (id: string, initialValue: TData): SyncBox => { - const state = getSyncBoxState(id); + return (id: string, initialValue: Value): SyncBox => { + const state = getSyncBoxState(id) as IObservableValue; state.set(initialValue); diff --git a/src/common/utils/sync-box/sync-box-injection-token.ts b/src/common/utils/sync-box/sync-box-injection-token.ts index 76ba0679f3..8db80243d3 100644 --- a/src/common/utils/sync-box/sync-box-injection-token.ts +++ b/src/common/utils/sync-box/sync-box-injection-token.ts @@ -4,21 +4,10 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; import type { IComputedValue } from "mobx"; - -type AsJson = T extends string | number | boolean | null - ? T - : T extends Function - ? never - : T extends Array - ? AsJson[] - : T extends object - ? { [K in keyof T]: AsJson } - : never; - -export interface SyncBox { +export interface SyncBox { id: string; - value: IComputedValue>; - set: (value: AsJson) => void; + value: IComputedValue; + set: (value: Value) => void; } export const syncBoxInjectionToken = getInjectionToken>({ diff --git a/src/main/start-main-application/lens-window/current-cluster-frame/current-cluster-frame.injectable.ts b/src/main/start-main-application/lens-window/current-cluster-frame/current-cluster-frame.injectable.ts index 2749b23253..e364b8cb0e 100644 --- a/src/main/start-main-application/lens-window/current-cluster-frame/current-cluster-frame.injectable.ts +++ b/src/main/start-main-application/lens-window/current-cluster-frame/current-cluster-frame.injectable.ts @@ -17,6 +17,10 @@ const currentClusterFrameInjectable = getInjectable({ return computed(() => { const clusterId = currentClusterFrameState.get(); + if (!clusterId) { + return undefined; + } + return clusterFrames.get(clusterId); }); }, diff --git a/src/renderer/components/+namespaces/store.ts b/src/renderer/components/+namespaces/store.ts index 1a242839fa..1b2342facf 100644 --- a/src/renderer/components/+namespaces/store.ts +++ b/src/renderer/components/+namespaces/store.ts @@ -114,7 +114,7 @@ export class NamespaceStore extends KubeObjectStore { * 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 */ - if (this.context.cluster.accessibleNamespaces.length > 0) { + if ((this.context?.cluster.accessibleNamespaces.length ?? 0) > 0) { return noop; } diff --git a/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts b/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts index 39d63e5d46..d49ea9dd9c 100644 --- a/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts +++ b/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; 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 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"; const provideInitialValuesForSyncBoxesInjectable = getInjectable({ @@ -14,7 +14,7 @@ const provideInitialValuesForSyncBoxesInjectable = getInjectable({ instantiate: (di) => { const requestFromChannel = di.inject(requestFromChannelInjectionToken); 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 { run: async () => { diff --git a/yarn.lock b/yarn.lock index 11e39924a8..7c32821446 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9090,10 +9090,10 @@ mobx-utils@^6.0.4: resolved "https://registry.yarnpkg.com/mobx-utils/-/mobx-utils-6.0.5.tgz#0cce9afb07fbba1fb559f959f8cea1f44baa7252" integrity sha512-QOduwicYedD4mwYZRl8+c3BalljFDcubg+PUGqBkn8tOuBoj2q7GhjXBP6JXM9J+Zh+2mePK8IoToeLfqr3Z/w== -mobx@^6.3.0, mobx@^6.5.0: - version "6.5.0" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.5.0.tgz#dc2d028b1882737f6e813fc92454381e438b7ad3" - integrity sha512-pHZ/cySF00FVENDWIDzJyoObFahK6Eg4d0papqm6d7yMkxWTZ/S/csqJX1A3PsYy4t5k3z2QnlwuCfMW5lSEwA== +mobx@^6.3.0, mobx@^6.6.0: + version "6.6.0" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.6.0.tgz#617ca1f3b745a781fa89c5eb94a773e3cbeff8ae" + integrity sha512-MNTKevLH/6DShLZcmSL351+JgiJPO56A4GUpoiDQ3/yZ0mAtclNLdHK9q4BcQhibx8/JSDupfTpbX2NZPemlRg== mock-fs@^5.1.2: version "5.1.2"