hydra/src/main/state-manager.ts

34 lines
802 B
TypeScript
Raw Normal View History

2024-04-20 16:11:35 +00:00
import type { Repack, RepackerFriendlyName, SteamGame } from "@main/entity";
2024-04-18 07:46:06 +00:00
interface State {
repacks: Repack[];
repackersFriendlyNames: RepackerFriendlyName[];
2024-04-20 16:11:35 +00:00
steamGames: SteamGame[];
2024-04-18 07:46:06 +00:00
eventResults: Map<[string, any[]], any>;
}
const initialState: State = {
repacks: [],
repackersFriendlyNames: [],
2024-04-20 16:11:35 +00:00
steamGames: [],
2024-04-18 07:46:06 +00:00
eventResults: new Map(),
};
export class StateManager {
private state = initialState;
public setValue<T extends keyof State>(key: T, value: State[T]) {
this.state = { ...this.state, [key]: value };
}
public getValue<T extends keyof State>(key: T) {
return this.state[key];
}
public clearValue<T extends keyof State>(key: T) {
this.state = { ...this.state, [key]: initialState[key] };
}
}
export const stateManager = new StateManager();