Replace a dependency to full implementation with an interface to allow minimal stubbing

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2021-12-28 11:51:34 +02:00
1 parent a9189f82e6
commit 13873f5d85
4 files changed
+72 -46

No files matched your search

@@ -18,15 +18,15 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { ExtensionLoader } from "./extension-loader";
import extensionsStoreInjectable from "../extensions-store/extensions-store.injectable";
import updateExtensionsStateInjectable from "./update-extensions-state/update-extensions-state.injectable";
const extensionLoaderInjectable = getInjectable({
instantiate: (di) => new ExtensionLoader({
extensionsStore: di.inject(extensionsStoreInjectable),
}),
instantiate: (di) =>
new ExtensionLoader({
updateExtensionsState: di.inject(updateExtensionsStateInjectable),
}),
lifecycle: lifecycleEnum.singleton,
});
@@ -30,10 +30,10 @@ import { Disposer, toJS } from "../../common/utils";
import logger from "../../main/logger";
import type { KubernetesCluster } from "../common-api/catalog";
import type { InstalledExtension } from "../extension-discovery/extension-discovery";
import type { ExtensionsStore } from "../extensions-store/extensions-store";
import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension";
import type { LensRendererExtension } from "../lens-renderer-extension";
import * as registries from "../registries";
import type { LensExtensionState } from "../extensions-store/extensions-store";
export function extensionPackagesRoot() {
return path.join(AppPaths.get("userData"));
@@ -42,7 +42,7 @@ export function extensionPackagesRoot() {
const logModule = "[EXTENSIONS-LOADER]";
interface Dependencies {
extensionsStore: ExtensionsStore
updateExtensionsState: (extensionsState: Record<LensExtensionId, LensExtensionState>) => void
}
/**
@@ -158,10 +158,13 @@ export class ExtensionLoader {
fireImmediately: true,
});
// save state on change `extension.isEnabled`
reaction(() => this.storeState, extensionsState => {
this.dependencies.extensionsStore.mergeState(extensionsState);
});
reaction(
() => this.storeState,
(state) => {
this.dependencies.updateExtensionsState(state);
},
);
}
initExtensions(extensions?: Map<LensExtensionId, InstalledExtension>) {
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import extensionsStoreInjectable from "../../extensions-store/extensions-store.injectable";
const updateExtensionsStateInjectable = getInjectable({
instantiate: (di) => di.inject(extensionsStoreInjectable).mergeState,
lifecycle: lifecycleEnum.singleton,
});
export default updateExtensionsStateInjectable;