mancala/frontend/src/context/context.tsx

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-07-30 16:32:13 +03:00
import { server } from "../const/config";
2022-07-14 13:38:00 +03:00
import { Texts, TrTr } from "../const/texts";
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 { UserKeyStore, UserKeyStoreImpl } from "../store/KeyStore";
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;
userKeyStore: UserKeyStore;
texts: Texts;
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 userKeyStore = new UserKeyStoreImpl({ httpService });
const gameStore = new GameStoreImpl({ httpService });
2022-05-15 01:58:57 +03:00
const texts = TrTr;
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,
userKeyStore: userKeyStore,
texts: texts,
themeManager,
2024-06-17 18:52:26 +03:00
gameStore,
storage
2022-05-15 01:58:57 +03:00
};
};