2024-05-14 15:54:14 +00:00
|
|
|
import type { Repack, SteamGame } from "@main/entity";
|
2024-04-21 05:26:29 +00:00
|
|
|
|
|
|
|
interface State {
|
|
|
|
repacks: Repack[];
|
|
|
|
steamGames: SteamGame[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const initialState: State = {
|
|
|
|
repacks: [],
|
|
|
|
steamGames: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|