Full dependency inversion of <Dock> and all current tab kinds (#4757)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Co-authored-by: Sebastian Malton <sebastian@malton.name>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
authored and GitHub committed 2022-01-31 09:49:36 -05:00
1 parent 65669f6a64
commit 0ce4e3d793
152 files changed
+3423 -2617

No files matched your search

+10 -8
View File
@@ -27,7 +27,6 @@ class WrappedAbortController extends AbortController {
interface SubscribeStoreParams {
store: KubeObjectStore<KubeObject>;
parent: AbortController;
watchChanges: boolean;
namespaces: string[];
onLoadFailure?: (err: any) => void;
}
@@ -75,7 +74,7 @@ export interface KubeWatchSubscribeStoreOptions {
/**
* A function that is called when listing fails. If set then blocks errors
* being rejected with
* from rejecting promises
*/
onLoadFailure?: (err: any) => void;
}
@@ -89,12 +88,16 @@ export class KubeWatchApi {
constructor(private dependencies: Dependencies) {}
private subscribeStore({ store, parent, watchChanges, namespaces, onLoadFailure }: SubscribeStoreParams): Disposer {
if (this.#watch.inc(store) > 1) {
private subscribeStore({ store, parent, namespaces, onLoadFailure }: SubscribeStoreParams): Disposer {
const isNamespaceFilterWatch = !namespaces;
if (isNamespaceFilterWatch && this.#watch.inc(store) > 1) {
// don't load or subscribe to a store more than once
return () => this.#watch.dec(store);
}
namespaces ??= this.dependencies.clusterFrameContext?.contextNamespaces ?? [];
let childController = new WrappedAbortController(parent);
const unsubscribe = disposer();
@@ -117,7 +120,7 @@ export class KubeWatchApi {
*/
loadThenSubscribe(namespaces).catch(noop);
const cancelReloading = watchChanges
const cancelReloading = isNamespaceFilterWatch && store.api.isNamespaced
? reaction(
// Note: must slice because reaction won't fire if it isn't there
() => [this.dependencies.clusterFrameContext.contextNamespaces.slice(), this.dependencies.clusterFrameContext.hasSelectedAll] as const,
@@ -141,7 +144,7 @@ export class KubeWatchApi {
: noop; // don't watch namespaces if namespaces were provided
return () => {
if (this.#watch.dec(store) === 0) {
if (isNamespaceFilterWatch && this.#watch.dec(store) === 0) {
// only stop the subcribe if this is the last one
cancelReloading();
childController.abort();
@@ -156,8 +159,7 @@ export class KubeWatchApi {
...stores.map(store => this.subscribeStore({
store,
parent,
watchChanges: !namespaces && store.api.isNamespaced,
namespaces: namespaces ?? this.dependencies.clusterFrameContext?.contextNamespaces ?? [],
namespaces,
onLoadFailure,
})),
);
@@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import kubeWatchApiInjectable from "./kube-watch-api.injectable";
const subscribeStoresInjectable = getInjectable({
instantiate: (di) => di.inject(kubeWatchApiInjectable).subscribeStores,
lifecycle: lifecycleEnum.singleton,
});
export default subscribeStoresInjectable;