mancala/apps/frontend/src/context/context.tsx

32 lines
1012 B
TypeScript
Raw Normal View History

import { keycloak, server } from "../const/config";
2024-06-17 18:52:26 +03:00
import { RTMT, RTMTWS, ThemeManager } from "@mancala/core";
2022-07-30 16:32:13 +03:00
import { HttpServiceImpl } from "../service/HttpService";
import { GameStore, GameStoreImpl } from "../store/GameStore";
import { AuthService } from "../auth/AuthService";
2024-06-17 18:52:26 +03:00
import { LocalStorage } from "../storage";
import { Storage } from '@mancala/core'
2021-06-27 19:28:55 +03:00
2022-05-15 01:58:57 +03:00
export type Context = {
rtmt: RTMT;
authService: AuthService;
2022-05-15 01:58:57 +03:00
themeManager: ThemeManager;
2022-07-30 16:32:13 +03:00
gameStore: GameStore;
2024-06-17 18:52:26 +03:00
storage: Storage;
2022-05-15 01:58:57 +03:00
};
2021-06-27 19:28:55 +03:00
2022-07-30 16:32:13 +03:00
export const initContext = (): Context => {
2022-05-15 01:58:57 +03:00
const rtmt = new RTMTWS();
2022-07-30 16:32:13 +03:00
const httpService = new HttpServiceImpl(server.serverAdress);
const authService = new AuthService({ keycloakUrl: keycloak.url, realm: keycloak.realm, clientId: keycloak.clientId });
2022-07-30 16:32:13 +03:00
const gameStore = new GameStoreImpl({ httpService });
2024-06-17 18:52:26 +03:00
const storage = new LocalStorage();
const themeManager = new ThemeManager(storage);
2022-05-15 01:58:57 +03:00
return {
rtmt: rtmt,
authService,
2022-05-15 01:58:57 +03:00
themeManager,
2024-06-17 18:52:26 +03:00
gameStore,
storage
2022-05-15 01:58:57 +03:00
};
};