mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Extract responsibility of setting dependencies to own injectable
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
88fe9b1b75
commit
3c7b2c9013
19
src/main/catalog-sources/sync-weblinks.injectable.ts
Normal file
19
src/main/catalog-sources/sync-weblinks.injectable.ts
Normal file
@ -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;
|
||||||
@ -33,7 +33,7 @@ interface Dependencies {
|
|||||||
catalogEntityRegistry: CatalogEntityRegistry;
|
catalogEntityRegistry: CatalogEntityRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function syncWeblinks({ weblinkStore, catalogEntityRegistry }: Dependencies) {
|
export const syncWeblinks = ({ weblinkStore, catalogEntityRegistry }: Dependencies) => () => {
|
||||||
const webLinkEntities = observable.map<string, [WebLink, Disposer]>();
|
const webLinkEntities = observable.map<string, [WebLink, Disposer]>();
|
||||||
|
|
||||||
function periodicallyCheckLink(link: WebLink): Disposer {
|
function periodicallyCheckLink(link: WebLink): Disposer {
|
||||||
@ -90,4 +90,4 @@ export function syncWeblinks({ weblinkStore, catalogEntityRegistry }: Dependenci
|
|||||||
}, { fireImmediately: true });
|
}, { fireImmediately: true });
|
||||||
|
|
||||||
catalogEntityRegistry.addComputedSource("weblinks", computed(() => Array.from(webLinkEntities.values(), ([link]) => link)));
|
catalogEntityRegistry.addComputedSource("weblinks", computed(() => Array.from(webLinkEntities.values(), ([link]) => link)));
|
||||||
}
|
};
|
||||||
|
|||||||
@ -3,21 +3,18 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
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 { whenApplicationIsLoadingInjectionToken } from "../runnable-tokens/when-application-is-loading-injection-token";
|
||||||
|
import syncWeblinksInjectable from "../../catalog-sources/sync-weblinks.injectable";
|
||||||
|
|
||||||
const setupSyncingOfWeblinksInjectable = getInjectable({
|
const setupSyncingOfWeblinksInjectable = getInjectable({
|
||||||
id: "setup-syncing-of-weblinks",
|
id: "setup-syncing-of-weblinks",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const weblinkStore = di.inject(weblinkStoreInjectable);
|
const syncWeblinks = di.inject(syncWeblinksInjectable);
|
||||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
run: () => {
|
run: () => {
|
||||||
syncWeblinks({ weblinkStore, catalogEntityRegistry });
|
syncWeblinks();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user