Created
July 25, 2023 17:29
-
-
Save oleh-zaporozhets/25407e3b9682145b7cb3f39a6497ebaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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