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

Mobx package upgrade (#4357)

This commit is contained in:
Roman 2021-11-25 19:02:59 +02:00 committed by Sebastian Malton
parent 817f8ca4f2
commit 6391d45ff4
7 changed files with 35 additions and 25 deletions

View File

@ -215,8 +215,8 @@
"mac-ca": "^1.0.6", "mac-ca": "^1.0.6",
"marked": "^2.1.3", "marked": "^2.1.3",
"md5-file": "^5.0.0", "md5-file": "^5.0.0",
"mobx": "^6.3.0", "mobx": "^6.3.7",
"mobx-observable-history": "^2.0.1", "mobx-observable-history": "^2.0.3",
"mobx-react": "^7.2.1", "mobx-react": "^7.2.1",
"mock-fs": "^4.14.0", "mock-fs": "^4.14.0",
"moment": "^2.29.1", "moment": "^2.29.1",

View File

@ -23,7 +23,7 @@ import path from "path";
import Config from "conf"; import Config from "conf";
import type { Options as ConfOptions } from "conf/dist/source/types"; import type { Options as ConfOptions } from "conf/dist/source/types";
import { ipcMain, ipcRenderer } from "electron"; import { ipcMain, ipcRenderer } from "electron";
import { IReactionOptions, makeObservable, reaction, runInAction } from "mobx"; import { IEqualsComparer, makeObservable, reaction, runInAction } from "mobx";
import { getAppVersion, Singleton, toJS, Disposer } from "./utils"; import { getAppVersion, Singleton, toJS, Disposer } from "./utils";
import logger from "../main/logger"; import logger from "../main/logger";
import { broadcastMessage, ipcMainOn, ipcRendererOn } from "./ipc"; import { broadcastMessage, ipcMainOn, ipcRendererOn } from "./ipc";
@ -33,7 +33,10 @@ import { kebabCase } from "lodash";
import { AppPaths } from "./app-paths"; import { AppPaths } from "./app-paths";
export interface BaseStoreParams<T> extends ConfOptions<T> { export interface BaseStoreParams<T> extends ConfOptions<T> {
syncOptions?: IReactionOptions; syncOptions?: {
fireImmediately?: boolean;
equals?: IEqualsComparer<T>;
};
} }
/** /**

View File

@ -29,7 +29,6 @@ export default function configurePackages() {
// Docs: https://mobx.js.org/configuration.html // Docs: https://mobx.js.org/configuration.html
Mobx.configure({ Mobx.configure({
enforceActions: "never", enforceActions: "never",
isolateGlobalState: true,
// TODO: enable later (read more: https://mobx.js.org/migrating-from-4-or-5.html) // TODO: enable later (read more: https://mobx.js.org/migrating-from-4-or-5.html)
// computedRequiresReaction: true, // computedRequiresReaction: true,

View File

@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import { action, comparer, computed, IReactionDisposer, IReactionOptions, makeObservable, reaction } from "mobx"; import { action, comparer, computed, IReactionDisposer, makeObservable, reaction } from "mobx";
import { autoBind, createStorage, noop, ToggleSet } from "../../utils"; import { autoBind, createStorage, noop, ToggleSet } from "../../utils";
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../../common/k8s-api/kube-object.store";
import { Namespace, namespacesApi } from "../../../common/k8s-api/endpoints/namespaces.api"; import { Namespace, namespacesApi } from "../../../common/k8s-api/endpoints/namespaces.api";
@ -45,10 +45,10 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
this.autoLoadAllowedNamespaces(); this.autoLoadAllowedNamespaces();
} }
public onContextChange(callback: (namespaces: string[]) => void, opts: IReactionOptions = {}): IReactionDisposer { public onContextChange(callback: (namespaces: string[]) => void, opts: { fireImmediately?: boolean } = {}): IReactionDisposer {
return reaction(() => Array.from(this.contextNamespaces), callback, { return reaction(() => Array.from(this.contextNamespaces), callback, {
fireImmediately: opts.fireImmediately,
equals: comparer.shallow, equals: comparer.shallow,
...opts,
}); });
} }
@ -205,7 +205,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
* explicitly deselected. * explicitly deselected.
* @param namespace The name of a namespace * @param namespace The name of a namespace
*/ */
toggleSingle(namespace: string){ toggleSingle(namespace: string) {
const nextState = new ToggleSet(this.contextNamespaces); const nextState = new ToggleSet(this.contextNamespaces);
nextState.toggle(namespace); nextState.toggle(namespace);

View File

@ -52,15 +52,12 @@ type Props = {};
@observer @observer
export class DeleteClusterDialog extends React.Component { export class DeleteClusterDialog extends React.Component {
showContextSwitch = false; @observable showContextSwitch = false;
newCurrentContext = ""; @observable newCurrentContext = "";
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
makeObservable(this, { makeObservable(this);
showContextSwitch: observable,
newCurrentContext: observable,
});
} }
static open({ config, cluster }: Partial<DialogState>) { static open({ config, cluster }: Partial<DialogState>) {

View File

@ -20,7 +20,7 @@
*/ */
import * as uuid from "uuid"; import * as uuid from "uuid";
import { action, comparer, computed, IReactionOptions, makeObservable, observable, reaction, runInAction } from "mobx"; import { action, comparer, computed, makeObservable, observable, reaction, runInAction } from "mobx";
import { autoBind, createStorage } from "../../utils"; import { autoBind, createStorage } from "../../utils";
import throttle from "lodash/throttle"; import throttle from "lodash/throttle";
@ -94,7 +94,11 @@ export interface DockTabChangeEvent {
prevTab?: DockTab; prevTab?: DockTab;
} }
export interface DockTabChangeEventOptions extends IReactionOptions { export interface DockTabChangeEventOptions {
/**
* apply a callback right after initialization
*/
fireImmediately?: boolean;
/** /**
* filter: by dockStore.selectedTab.kind == tabKind * filter: by dockStore.selectedTab.kind == tabKind
*/ */
@ -195,11 +199,13 @@ export class DockStore implements DockStorageState {
if (this.height > this.maxHeight) this.height = this.maxHeight; if (this.height > this.maxHeight) this.height = this.maxHeight;
} }
onResize(callback: () => void, options?: IReactionOptions) { onResize(callback: () => void, opts: { fireImmediately?: boolean } = {}) {
return reaction(() => [this.height, this.fullSize], callback, options); return reaction(() => [this.height, this.fullSize], callback, {
fireImmediately: opts.fireImmediately,
});
} }
onTabClose(callback: (evt: DockTabCloseEvent) => void, options: IReactionOptions = {}) { onTabClose(callback: (evt: DockTabCloseEvent) => void, opts: { fireImmediately?: boolean } = {}) {
return reaction(() => dockStore.tabs.map(tab => tab.id), (tabs: TabId[], prevTabs?: TabId[]) => { return reaction(() => dockStore.tabs.map(tab => tab.id), (tabs: TabId[], prevTabs?: TabId[]) => {
if (!Array.isArray(prevTabs)) { if (!Array.isArray(prevTabs)) {
return; // tabs not yet modified return; // tabs not yet modified
@ -214,7 +220,7 @@ export class DockStore implements DockStorageState {
} }
}, { }, {
equals: comparer.structural, equals: comparer.structural,
...options, fireImmediately: opts.fireImmediately,
}); });
} }

View File

@ -9535,10 +9535,10 @@ mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.4, mkdirp@^0.5.5, mkdirp@~0.5.0:
dependencies: dependencies:
minimist "^1.2.5" minimist "^1.2.5"
mobx-observable-history@^2.0.1: mobx-observable-history@^2.0.3:
version "2.0.1" version "2.0.3"
resolved "https://registry.yarnpkg.com/mobx-observable-history/-/mobx-observable-history-2.0.1.tgz#bb39f19346e094c3608bbfba4b2b0aca985a562f" resolved "https://registry.yarnpkg.com/mobx-observable-history/-/mobx-observable-history-2.0.3.tgz#07dd551e9d2a5666ca1d759ad108173fab47125e"
integrity sha512-ijNuz2iBl5SYRdvVIqK3yeRJEGxWS7Oqq14ideNUDAvNZUBk/iCOmzWMgR6vfwp3bYieX/6tANS8N6RjVTKwGg== integrity sha512-cWMG3GcT1l2Y880mfffNh9m6WldQyOtlLUvcdVUjIj++sNOQbRxKBaBUe/TPDiJ80EN6g8FGiVuFlzzyRJPykQ==
dependencies: dependencies:
"@types/history" "^4.7.8" "@types/history" "^4.7.8"
history "^4.10.1" history "^4.10.1"
@ -9561,6 +9561,11 @@ mobx@^6.3.0:
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.0.tgz#a8fb693c3047bdfcb1eaff9aa48e36a7eb084f96" resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.0.tgz#a8fb693c3047bdfcb1eaff9aa48e36a7eb084f96"
integrity sha512-Aa1+VXsg4WxqJMTQfWoYuJi5UD10VZhiobSmcs5kcmI3BIT0aVtn7DysvCeDADCzl7dnbX+0BTHUj/v7gLlZpQ== integrity sha512-Aa1+VXsg4WxqJMTQfWoYuJi5UD10VZhiobSmcs5kcmI3BIT0aVtn7DysvCeDADCzl7dnbX+0BTHUj/v7gLlZpQ==
mobx@^6.3.7:
version "6.3.7"
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.7.tgz#9ed85561e86da45141134c8fa20cf5f9c7246c3d"
integrity sha512-X7yU7eOEyxIBk4gjIi2UIilwdw48gXh0kcZ5ex3Rc+COJsJmJ4SNpf42uYea3aUqb1hedTv5xzJrq5Q55p0P5g==
mock-fs@^4.14.0: mock-fs@^4.14.0:
version "4.14.0" version "4.14.0"
resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.14.0.tgz#ce5124d2c601421255985e6e94da80a7357b1b18" resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.14.0.tgz#ce5124d2c601421255985e6e94da80a7357b1b18"