Skip to content

Instantly share code, notes, and snippets.

@oleh-zaporozhets
Created July 25, 2023 17:29
Show Gist options
  • Save oleh-zaporozhets/25407e3b9682145b7cb3f39a6497ebaa to your computer and use it in GitHub Desktop.
Save oleh-zaporozhets/25407e3b9682145b7cb3f39a6497ebaa to your computer and use it in GitHub Desktop.
import { ITimer } from './timer';
interface ITimerStore {
getTimerById(id: string): ITimer | null;
addTimer(id: string, timer: ITimer): void;
}
class TimerStore implements ITimerStore {
private timers: Map<string, ITimer>;
public constructor() {
this.timers = new Map<string, ITimer>();
}
public getTimerById(id: string): ITimer | null {
const timer = this.timers.get(id);
return timer || null;
}
public addTimer(id: string, timer: ITimer): void {
if (this.timers.has(id)) {
throw new Error(`Timer with id ${id} was created already.`);
}
this.timers.set(id, timer);
}
}
export { ITimerStore, TimerStore };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment