From 3c7b2c9013751e28c822d9b160c6e1b6e9b610b0 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Thu, 5 May 2022 08:30:44 +0300 Subject: [PATCH] Extract responsibility of setting dependencies to own injectable Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- .../sync-weblinks.injectable.ts | 19 +++++++++++++++++++ src/main/catalog-sources/weblinks.ts | 4 ++-- .../setup-syncing-of-weblinks.injectable.ts | 9 +++------ 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 src/main/catalog-sources/sync-weblinks.injectable.ts diff --git a/src/main/catalog-sources/sync-weblinks.injectable.ts b/src/main/catalog-sources/sync-weblinks.injectable.ts new file mode 100644 index 0000000000..f789427842 --- /dev/null +++ b/src/main/catalog-sources/sync-weblinks.injectable.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable } from "@ogre-tools/injectable"; +import { syncWeblinks } from "./weblinks"; +import weblinkStoreInjectable from "../../common/weblink-store.injectable"; +import catalogEntityRegistryInjectable from "../catalog/catalog-entity-registry.injectable"; + +const syncWeblinksInjectable = getInjectable({ + id: "sync-weblinks", + + instantiate: (di) => syncWeblinks({ + weblinkStore: di.inject(weblinkStoreInjectable), + catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable), + }), +}); + +export default syncWeblinksInjectable; diff --git a/src/main/catalog-sources/weblinks.ts b/src/main/catalog-sources/weblinks.ts index ec8bf88d24..353f5f91bb 100644 --- a/src/main/catalog-sources/weblinks.ts +++ b/src/main/catalog-sources/weblinks.ts @@ -33,7 +33,7 @@ interface Dependencies { catalogEntityRegistry: CatalogEntityRegistry; } -export function syncWeblinks({ weblinkStore, catalogEntityRegistry }: Dependencies) { +export const syncWeblinks = ({ weblinkStore, catalogEntityRegistry }: Dependencies) => () => { const webLinkEntities = observable.map(); function periodicallyCheckLink(link: WebLink): Disposer { @@ -90,4 +90,4 @@ export function syncWeblinks({ weblinkStore, catalogEntityRegistry }: Dependenci }, { fireImmediately: true }); catalogEntityRegistry.addComputedSource("weblinks", computed(() => Array.from(webLinkEntities.values(), ([link]) => link))); -} +}; diff --git a/src/main/start-main-application/runnables/setup-syncing-of-weblinks.injectable.ts b/src/main/start-main-application/runnables/setup-syncing-of-weblinks.injectable.ts index 3268239bee..8d8e1e9f5a 100644 --- a/src/main/start-main-application/runnables/setup-syncing-of-weblinks.injectable.ts +++ b/src/main/start-main-application/runnables/setup-syncing-of-weblinks.injectable.ts @@ -3,21 +3,18 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { syncWeblinks } from "../../catalog-sources"; -import weblinkStoreInjectable from "../../../common/weblink-store.injectable"; -import catalogEntityRegistryInjectable from "../../catalog/catalog-entity-registry.injectable"; import { whenApplicationIsLoadingInjectionToken } from "../runnable-tokens/when-application-is-loading-injection-token"; +import syncWeblinksInjectable from "../../catalog-sources/sync-weblinks.injectable"; const setupSyncingOfWeblinksInjectable = getInjectable({ id: "setup-syncing-of-weblinks", instantiate: (di) => { - const weblinkStore = di.inject(weblinkStoreInjectable); - const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); + const syncWeblinks = di.inject(syncWeblinksInjectable); return { run: () => { - syncWeblinks({ weblinkStore, catalogEntityRegistry }); + syncWeblinks(); }, }; },