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 { app, ipcMain, IpcMainEvent, ipcRenderer, IpcRendererEvent, remote } from "electron";
|
||||
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 { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
||||
import isEqual from "lodash/isEqual";
|
||||
|
||||
// FIXME: sync/saving doesn't work
|
||||
|
||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||
autoLoad?: boolean;
|
||||
syncEnabled?: boolean;
|
||||
@ -21,14 +19,18 @@ export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||
*/
|
||||
export abstract class BaseStore<T = any> extends Singleton {
|
||||
protected storeConfig?: Config<T>;
|
||||
protected syncDisposers: Function[] = [];
|
||||
protected syncDisposers: Disposer[] = [];
|
||||
|
||||
whenLoaded = when(() => this.isLoaded);
|
||||
@observable isLoaded = false;
|
||||
|
||||
get whenLoaded() {
|
||||
return when(() => this.isLoaded);
|
||||
}
|
||||
|
||||
protected constructor(protected params: BaseStoreParams) {
|
||||
super();
|
||||
makeObservable(this);
|
||||
|
||||
this.params = {
|
||||
autoLoad: false,
|
||||
syncEnabled: true,
|
||||
|
||||
@ -65,7 +65,10 @@ export class ExtensionDiscovery extends Singleton {
|
||||
|
||||
// True if extensions have been loaded from the disk after app startup
|
||||
@observable isLoaded = false;
|
||||
whenLoaded = when(() => this.isLoaded);
|
||||
|
||||
get whenLoaded() {
|
||||
return when(() => this.isLoaded);
|
||||
}
|
||||
|
||||
// IPC channel to broadcast changes to extension-discovery from main
|
||||
protected static readonly extensionDiscoveryChannel = "extension-discovery:main";
|
||||
|
||||
@ -37,7 +37,10 @@ export class ExtensionLoader extends Singleton {
|
||||
private events = new EventEmitter();
|
||||
|
||||
@observable isLoaded = false;
|
||||
whenLoaded = when(() => this.isLoaded);
|
||||
|
||||
get whenLoaded() {
|
||||
return when(() => this.isLoaded);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@ -71,7 +71,9 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
protected activated = false;
|
||||
private resourceAccessStatuses: Map<KubeApiResource, boolean> = new Map();
|
||||
|
||||
whenReady = when(() => this.ready);
|
||||
get whenReady() {
|
||||
return when(() => this.ready);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kubeconfig context name
|
||||
|
||||
@ -5,7 +5,7 @@ import type { KubeObjectStore } from "../kube-object.store";
|
||||
import type { ClusterContext } from "../components/context";
|
||||
|
||||
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 { KubeApi } from "./kube-api";
|
||||
import { KubeJsonApiData } from "./kube-json-api";
|
||||
@ -32,8 +32,6 @@ export interface IKubeWatchLog {
|
||||
export class KubeWatchApi {
|
||||
@observable context: ClusterContext = null;
|
||||
|
||||
contextReady = when(() => Boolean(this.context));
|
||||
|
||||
constructor() {
|
||||
makeObservable(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 { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
|
||||
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
||||
@ -24,7 +24,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
||||
|
||||
private async init() {
|
||||
await this.contextReady;
|
||||
await when(() => this.storage.initialized);
|
||||
await this.storage.whenReady;
|
||||
|
||||
this.setContext(this.initialNamespaces);
|
||||
this.autoLoadAllowedNamespaces();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
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 { KubeObject, KubeStatus } from "./api/kube-object";
|
||||
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;
|
||||
@observable private loadedNamespaces?: string[];
|
||||
|
||||
contextReady = when(() => Boolean(this.context));
|
||||
namespacesReady = when(() => Boolean(this.loadedNamespaces));
|
||||
get contextReady() {
|
||||
return when(() => Boolean(this.context));
|
||||
}
|
||||
|
||||
get namespacesReady() {
|
||||
return when(() => Boolean(this.loadedNamespaces));
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@ -114,8 +119,8 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
||||
}
|
||||
|
||||
const isLoadingAll = this.context.allNamespaces?.length > 1
|
||||
&& this.context.cluster.accessibleNamespaces.length === 0
|
||||
&& this.context.allNamespaces.every(ns => namespaces.includes(ns));
|
||||
&& this.context.cluster.accessibleNamespaces.length === 0
|
||||
&& this.context.allNamespaces.every(ns => namespaces.includes(ns));
|
||||
|
||||
if (isLoadingAll) {
|
||||
this.loadedNamespaces = [];
|
||||
|
||||
@ -26,7 +26,10 @@ export class StorageHelper<T> {
|
||||
private data: IObservableValue<T>;
|
||||
|
||||
@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 {
|
||||
// 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>) {
|
||||
const { storage, defaultValue, autoInit = true } = options;
|
||||
|
||||
makeObservable(this);
|
||||
|
||||
this.storage = storage;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user