mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-28 21:31:03 +00:00
first commit
This commit is contained in:
31
src/main/state-manager.ts
Normal file
31
src/main/state-manager.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Repack, RepackerFriendlyName } from "@main/entity";
|
||||
|
||||
interface State {
|
||||
repacks: Repack[];
|
||||
repackersFriendlyNames: RepackerFriendlyName[];
|
||||
eventResults: Map<[string, any[]], any>;
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
repacks: [],
|
||||
repackersFriendlyNames: [],
|
||||
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();
|
||||
Reference in New Issue
Block a user