Skip to content

Commit

Permalink
Refactor using redux-clean-architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Garrone authored and Joseph Garrone committed Sep 14, 2023
1 parent 479e63e commit 0d67ebc
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 230 deletions.
2 changes: 2 additions & 0 deletions drama-queen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.14.6",
"@reduxjs/toolkit": "^1.9.5",
"@tanstack/react-query": "^4.29.19",
"@tanstack/react-query-devtools": "^4.33.0",
"@types/memoizee": "^0.4.8",
Expand All @@ -26,6 +27,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1",
"redux-clean-architecture": "^3.7.2",
"tsafe": "^1.6.4",
"tss-react": "^4.9.0",
"zod": "^3.21.4"
Expand Down
11 changes: 6 additions & 5 deletions drama-queen/src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from "react";
import { initializeCore } from "core"
import { createCoreProvider } from "core";
import { createRoot } from "react-dom/client";
import { RouterProvider } from "react-router-dom";
import { type RoutingStrategy, createRouter } from "ui/routing/createRouter";
Expand All @@ -24,14 +24,15 @@ const { QueenApiProvider } = createQueenApiProvider({
apiUrl: import.meta.env.VITE_QUEEN_API_URL
});

const { CoreLoadingFallback } = initializeCore({
const { CoreProvider } = createCoreProvider({
"apiUrl": import.meta.env.VITE_API_URL,
"keycloakParams": {
"url": import.meta.env.VITE_KEYCLOAK_URL,
"clientId": import.meta.env.VITE_KEYCLOAK_CLIENT_ID,
"realm": import.meta.env.VITE_KEYCLOAK_REALM,
"origin": window.location.origin + import.meta.env.BASE_URL
}
},
"redirectUrl": import.meta.env.VITE_REDIRECT_URL,
});

const mount = ({
Expand Down Expand Up @@ -60,9 +61,9 @@ const mount = ({
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
*/
<CoreLoadingFallback fallback={<h1>Loading</h1>} >
<CoreProvider fallback={<h1>Loading</h1>} >
<LoadingData />
</CoreLoadingFallback>
</CoreProvider>
);

return () => queueMicrotask(() => root.unmount());
Expand Down
35 changes: 0 additions & 35 deletions drama-queen/src/core/core.ts

This file was deleted.

19 changes: 19 additions & 0 deletions drama-queen/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
NOTE: Only here do we export the API for a specific framework (here react).
In the rest of the core directory everything is agnostic to React
*/
import { createReactApi } from "redux-clean-architecture/react";
import { createCore } from "./setup";
import { usecases } from "./usecases";

export const {
createCoreProvider,
selectors,
useCoreEvts,
useCoreExtras,
useCoreFunctions,
useCoreState
} = createReactApi({
createCore,
usecases
});
94 changes: 0 additions & 94 deletions drama-queen/src/core/index.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions drama-queen/src/core/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import { createCoreFromUsecases } from "redux-clean-architecture";
import type { GenericCreateEvt, GenericThunks } from "redux-clean-architecture";
import { createApiClient } from "./queenApi/createApiClient";
import { createKeycloakClient } from "./keycloakClient/createKeycloakClient";
import { usecases } from "./usecases";

type CoreParams = {
apiUrl: string;
keycloakParams: {
url: string;
clientId: string;
realm: string;
origin?: string;
};
redirectUrl: string;
};

export async function createCore(params: CoreParams) {

const { apiUrl, keycloakParams } = params;

const oidc = await createKeycloakClient(keycloakParams);

const queenApi = createApiClient({
apiUrl,
"getAccessToken": !oidc.isUserLoggedIn ?
(() => null) :
(() => oidc.getAccessToken())
});

const core = createCoreFromUsecases({
"thunksExtraArgument": {
"coreParams": params,
oidc,
queenApi
},
usecases
});

return core;
}

type Core = Awaited<ReturnType<typeof createCore>>;

export type State = ReturnType<Core["getState"]>;

export type Thunks = GenericThunks<Core>;

export type CreateEvt = GenericCreateEvt<Core>;
4 changes: 4 additions & 0 deletions drama-queen/src/core/usecases/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import * as loadingData from "./loadingData";

export const usecases = { loadingData };
Loading

0 comments on commit 0d67ebc

Please sign in to comment.