mirror of
https://github.com/asyouplz/SpeechNote.git
synced 2026-07-22 16:30:31 +00:00
Apply repository formatting to satisfy CI format check. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
42 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
}
|
|
}
|