From e36f3d2d7043dc60d78cfcbca93aa67cab6bb3d2 Mon Sep 17 00:00:00 2001 From: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com> Date: Tue, 20 Dec 2022 15:38:20 +0200 Subject: [PATCH] Navigation logging injectable (#6797) Move navigation logging to `setupLoggingForNavigationInjectable` to prevent cycle of injectables from occurring. Wasn't eventually needed for #6795 but still an improvement. Credit for the implementation goes to @Nokel81 , thanks! Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com> Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com> --- .../observable-history.injectable.ts | 9 ----- ...setup-logging-for-navigation.injectable.ts | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/renderer/navigation/setup-logging-for-navigation.injectable.ts diff --git a/src/renderer/navigation/observable-history.injectable.ts b/src/renderer/navigation/observable-history.injectable.ts index 81d9df2dd1..c813c675fd 100644 --- a/src/renderer/navigation/observable-history.injectable.ts +++ b/src/renderer/navigation/observable-history.injectable.ts @@ -4,7 +4,6 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { createObservableHistory } from "mobx-observable-history"; -import loggerInjectable from "../../common/logger.injectable"; import { searchParamsOptions } from "./search-params"; import historyInjectable from "./history.injectable"; @@ -13,18 +12,10 @@ const observableHistoryInjectable = getInjectable({ instantiate: (di) => { const history = di.inject(historyInjectable); - const logger = di.inject(loggerInjectable); const navigation = createObservableHistory(history, { searchParams: searchParamsOptions, }); - navigation.listen((location, action) => { - const isClusterView = !process.isMainFrame; - const domain = global.location.href; - - logger.debug(`[NAVIGATION]: ${action}-ing. Current is now:`, { isClusterView, domain, location }); - }); - return navigation; }, }); diff --git a/src/renderer/navigation/setup-logging-for-navigation.injectable.ts b/src/renderer/navigation/setup-logging-for-navigation.injectable.ts new file mode 100644 index 0000000000..b769b92db1 --- /dev/null +++ b/src/renderer/navigation/setup-logging-for-navigation.injectable.ts @@ -0,0 +1,33 @@ +/** + * 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 loggerInjectable from "../../common/logger.injectable"; +import { beforeFrameStartsInjectionToken } from "../before-frame-starts/tokens"; +import observableHistoryInjectable from "./observable-history.injectable"; + +const setupLoggingForNavigationInjectable = getInjectable({ + id: "setup-logging-for-navigation", + instantiate: (di) => ({ + id: "setup-logging-for-navigation", + run: () => { + const logger = di.inject(loggerInjectable); + const observableHistory = di.inject(observableHistoryInjectable); + + observableHistory.listen((location, action) => { + const isClusterView = !process.isMainFrame; + const domain = global.location.href; + + logger.debug(`[NAVIGATION]: ${action}-ing. Current is now:`, { + isClusterView, + domain, + location, + }); + }); + }, + }), + injectionToken: beforeFrameStartsInjectionToken, +}); + +export default setupLoggingForNavigationInjectable;