-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor using redux-clean-architecture
- Loading branch information
Joseph Garrone
authored and
Joseph Garrone
committed
Sep 14, 2023
1 parent
479e63e
commit 0d67ebc
Showing
10 changed files
with
314 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
import * as loadingData from "./loadingData"; | ||
|
||
export const usecases = { loadingData }; |
Oops, something went wrong.