Skip to content

Commit

Permalink
Navigation logging injectable
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
samitiilikainen committed Dec 20, 2022
1 parent 56197d8 commit aea9232
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/renderer/navigation/observable-history.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
},
});
Expand Down
33 changes: 33 additions & 0 deletions src/renderer/navigation/setup-logging-for-navigation.injectable.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit aea9232

Please sign in to comment.