Skip to content

Commit

Permalink
refactor: rename App to Main component to follow clean architecture b…
Browse files Browse the repository at this point in the history
…ook language
  • Loading branch information
adbayb committed Dec 25, 2024
1 parent ee0fbf2 commit edd392a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 2 additions & 4 deletions hosts/web/src/App.tsx → hosts/web/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// eslint-disable-next-line import-x/no-namespace
import * as Catalog from "@clean-architecture/catalog";

export const App = () => {
export const Main = () => {
return (
<Catalog.DependencyInjection
quoteEntityGateway={new Catalog.QuoteEntityGateway()} // TODO: move it internally?
>
<Catalog.DependencyInjection>
<Catalog.GetQuoteView />
</Catalog.DependencyInjection>
);
Expand Down
4 changes: 2 additions & 2 deletions hosts/web/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createRoot } from "react-dom/client";
import { StrictMode } from "react";

import { App } from "./App";
import { Main } from "./Main";

const rootElement = document.querySelector("#root");

if (rootElement) {
createRoot(rootElement).render(
<StrictMode>
<App />
<Main />
</StrictMode>,
);
}
17 changes: 9 additions & 8 deletions modules/catalog/src/frameworks/web/useDependencyInjection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, useContext } from "react";
import type { PropsWithChildren } from "react";
import { Guard } from "@clean-architecture/shared-kernel";

import type { QuoteEntityGateway } from "../../adapters/QuoteEntityGateway";
import { QuoteEntityGateway } from "../../adapters/QuoteEntityGateway";

type DependencyInjectionContextValue = {
readonly quoteEntityGateway: QuoteEntityGateway;
Expand All @@ -11,15 +11,16 @@ type DependencyInjectionContextValue = {
const DependencyInjectionContext =
createContext<DependencyInjectionContextValue | null>(null);

type DependencyInjectionProps =
PropsWithChildren<DependencyInjectionContextValue>;
// TODO: add data source as props to enable test vs. real host
type DependencyInjectionProps = PropsWithChildren;

export const DependencyInjection = ({
children,
...contextValue
}: DependencyInjectionProps) => {
const CONTEXT_VALUE: DependencyInjectionContextValue = {
quoteEntityGateway: new QuoteEntityGateway(),
};

export const DependencyInjection = ({ children }: DependencyInjectionProps) => {
return (
<DependencyInjectionContext.Provider value={contextValue}>
<DependencyInjectionContext.Provider value={CONTEXT_VALUE}>
{children}
</DependencyInjectionContext.Provider>
);
Expand Down

0 comments on commit edd392a

Please sign in to comment.