mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: don't cache mobx.when(() => this.someObservable) cause might not work as expected due later call of makeObservable(this) in constructor
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
3357269c5d
commit
ed1f88b5d8
@ -3,13 +3,11 @@ import Config from "conf";
|
|||||||
import { Options as ConfOptions } from "conf/dist/source/types";
|
import { Options as ConfOptions } from "conf/dist/source/types";
|
||||||
import { app, ipcMain, IpcMainEvent, ipcRenderer, IpcRendererEvent, remote } from "electron";
|
import { app, ipcMain, IpcMainEvent, ipcRenderer, IpcRendererEvent, remote } from "electron";
|
||||||
import { IReactionOptions, makeObservable, observable, reaction, runInAction, when } from "mobx";
|
import { IReactionOptions, makeObservable, observable, reaction, runInAction, when } from "mobx";
|
||||||
import { getAppVersion, Singleton, toJS } from "./utils";
|
import { getAppVersion, Singleton, toJS, Disposer } from "./utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
|
|
||||||
// FIXME: sync/saving doesn't work
|
|
||||||
|
|
||||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||||
autoLoad?: boolean;
|
autoLoad?: boolean;
|
||||||
syncEnabled?: boolean;
|
syncEnabled?: boolean;
|
||||||
@ -21,14 +19,18 @@ export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
|||||||
*/
|
*/
|
||||||
export abstract class BaseStore<T = any> extends Singleton {
|
export abstract class BaseStore<T = any> extends Singleton {
|
||||||
protected storeConfig?: Config<T>;
|
protected storeConfig?: Config<T>;
|
||||||
protected syncDisposers: Function[] = [];
|
protected syncDisposers: Disposer[] = [];
|
||||||
|
|
||||||
whenLoaded = when(() => this.isLoaded);
|
|
||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
|
|
||||||
|
get whenLoaded() {
|
||||||
|
return when(() => this.isLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
protected constructor(protected params: BaseStoreParams) {
|
protected constructor(protected params: BaseStoreParams) {
|
||||||
super();
|
super();
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
|
|
||||||
this.params = {
|
this.params = {
|
||||||
autoLoad: false,
|
autoLoad: false,
|
||||||
syncEnabled: true,
|
syncEnabled: true,
|
||||||
|
|||||||
@ -65,7 +65,10 @@ export class ExtensionDiscovery extends Singleton {
|
|||||||
|
|
||||||
// True if extensions have been loaded from the disk after app startup
|
// True if extensions have been loaded from the disk after app startup
|
||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
whenLoaded = when(() => this.isLoaded);
|
|
||||||
|
get whenLoaded() {
|
||||||
|
return when(() => this.isLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
// IPC channel to broadcast changes to extension-discovery from main
|
// IPC channel to broadcast changes to extension-discovery from main
|
||||||
protected static readonly extensionDiscoveryChannel = "extension-discovery:main";
|
protected static readonly extensionDiscoveryChannel = "extension-discovery:main";
|
||||||
|
|||||||
@ -37,7 +37,10 @@ export class ExtensionLoader extends Singleton {
|
|||||||
private events = new EventEmitter();
|
private events = new EventEmitter();
|
||||||
|
|
||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
whenLoaded = when(() => this.isLoaded);
|
|
||||||
|
get whenLoaded() {
|
||||||
|
return when(() => this.isLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -71,7 +71,9 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
protected activated = false;
|
protected activated = false;
|
||||||
private resourceAccessStatuses: Map<KubeApiResource, boolean> = new Map();
|
private resourceAccessStatuses: Map<KubeApiResource, boolean> = new Map();
|
||||||
|
|
||||||
whenReady = when(() => this.ready);
|
get whenReady() {
|
||||||
|
return when(() => this.ready);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kubeconfig context name
|
* Kubeconfig context name
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import type { KubeObjectStore } from "../kube-object.store";
|
|||||||
import type { ClusterContext } from "../components/context";
|
import type { ClusterContext } from "../components/context";
|
||||||
|
|
||||||
import plimit from "p-limit";
|
import plimit from "p-limit";
|
||||||
import { comparer, IReactionDisposer, observable, reaction, when, makeObservable } from "mobx";
|
import { comparer, IReactionDisposer, observable, reaction, makeObservable } from "mobx";
|
||||||
import { autoBind, noop } from "../utils";
|
import { autoBind, noop } from "../utils";
|
||||||
import { KubeApi } from "./kube-api";
|
import { KubeApi } from "./kube-api";
|
||||||
import { KubeJsonApiData } from "./kube-json-api";
|
import { KubeJsonApiData } from "./kube-json-api";
|
||||||
@ -32,8 +32,6 @@ export interface IKubeWatchLog {
|
|||||||
export class KubeWatchApi {
|
export class KubeWatchApi {
|
||||||
@observable context: ClusterContext = null;
|
@observable context: ClusterContext = null;
|
||||||
|
|
||||||
contextReady = when(() => Boolean(this.context));
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
autoBind(this);
|
autoBind(this);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { action, comparer, computed, IReactionDisposer, IReactionOptions, makeObservable, reaction, when, } from "mobx";
|
import { action, comparer, computed, IReactionDisposer, IReactionOptions, makeObservable, reaction, } from "mobx";
|
||||||
import { autoBind, createStorage } from "../../utils";
|
import { autoBind, createStorage } from "../../utils";
|
||||||
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
|
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
|
||||||
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
||||||
@ -24,7 +24,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
await this.contextReady;
|
await this.contextReady;
|
||||||
await when(() => this.storage.initialized);
|
await this.storage.whenReady;
|
||||||
|
|
||||||
this.setContext(this.initialNamespaces);
|
this.setContext(this.initialNamespaces);
|
||||||
this.autoLoadAllowedNamespaces();
|
this.autoLoadAllowedNamespaces();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { ClusterContext } from "./components/context";
|
import type { ClusterContext } from "./components/context";
|
||||||
|
|
||||||
import { action, computed, observable, reaction, when, makeObservable } from "mobx";
|
import { action, computed, makeObservable, observable, reaction, when } from "mobx";
|
||||||
import { autoBind, bifurcateArray, noop, rejectPromiseBy } from "./utils";
|
import { autoBind, bifurcateArray, noop, rejectPromiseBy } from "./utils";
|
||||||
import { KubeObject, KubeStatus } from "./api/kube-object";
|
import { KubeObject, KubeStatus } from "./api/kube-object";
|
||||||
import { IKubeWatchEvent } from "./api/kube-watch-api";
|
import { IKubeWatchEvent } from "./api/kube-watch-api";
|
||||||
@ -24,8 +24,13 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
public readonly bufferSize: number = 50000;
|
public readonly bufferSize: number = 50000;
|
||||||
@observable private loadedNamespaces?: string[];
|
@observable private loadedNamespaces?: string[];
|
||||||
|
|
||||||
contextReady = when(() => Boolean(this.context));
|
get contextReady() {
|
||||||
namespacesReady = when(() => Boolean(this.loadedNamespaces));
|
return when(() => Boolean(this.context));
|
||||||
|
}
|
||||||
|
|
||||||
|
get namespacesReady() {
|
||||||
|
return when(() => Boolean(this.loadedNamespaces));
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -114,8 +119,8 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isLoadingAll = this.context.allNamespaces?.length > 1
|
const isLoadingAll = this.context.allNamespaces?.length > 1
|
||||||
&& this.context.cluster.accessibleNamespaces.length === 0
|
&& this.context.cluster.accessibleNamespaces.length === 0
|
||||||
&& this.context.allNamespaces.every(ns => namespaces.includes(ns));
|
&& this.context.allNamespaces.every(ns => namespaces.includes(ns));
|
||||||
|
|
||||||
if (isLoadingAll) {
|
if (isLoadingAll) {
|
||||||
this.loadedNamespaces = [];
|
this.loadedNamespaces = [];
|
||||||
|
|||||||
@ -26,7 +26,10 @@ export class StorageHelper<T> {
|
|||||||
private data: IObservableValue<T>;
|
private data: IObservableValue<T>;
|
||||||
|
|
||||||
@observable initialized = false;
|
@observable initialized = false;
|
||||||
whenReady = when(() => this.initialized); // FIXME: invalid, use when() at the place of usage
|
|
||||||
|
get whenReady() {
|
||||||
|
return when(() => this.initialized);
|
||||||
|
}
|
||||||
|
|
||||||
get defaultValue(): T {
|
get defaultValue(): T {
|
||||||
// return as-is since options.defaultValue might be a getter too
|
// return as-is since options.defaultValue might be a getter too
|
||||||
@ -35,6 +38,7 @@ export class StorageHelper<T> {
|
|||||||
|
|
||||||
constructor(readonly key: string, private options: StorageHelperOptions<T>) {
|
constructor(readonly key: string, private options: StorageHelperOptions<T>) {
|
||||||
const { storage, defaultValue, autoInit = true } = options;
|
const { storage, defaultValue, autoInit = true } = options;
|
||||||
|
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
|
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user