asyouplz_SpeechNote/src/application/StateManager.ts
asyouplz 07d8f3cdce chore(format): run prettier
Apply repository formatting to satisfy CI format check.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 00:10:37 +09:00

42 lines
1.1 KiB
TypeScript

import type { IStateManager, AppState, StateListener, Unsubscribe } from '../types';
export class StateManager implements IStateManager {
private state: AppState = {
status: 'idle',
currentFile: null,
progress: 0,
error: null,
history: [],
};
private listeners: Set<StateListener> = new Set();
getState(): Readonly<AppState> {
return Object.freeze({ ...this.state });
}
setState(updates: Partial<AppState>): void {
const prevState = { ...this.state };
this.state = { ...this.state, ...updates };
this.notifyListeners(prevState);
}
subscribe(listener: StateListener): Unsubscribe {
this.listeners.add(listener);
return () => this.listeners.delete(listener);
}
reset(): void {
this.setState({
status: 'idle',
currentFile: null,
progress: 0,
error: null,
});
}
private notifyListeners(prevState: AppState): void {
this.listeners.forEach((listener) => {
listener(this.state, prevState);
});
}
}