Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 28, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/e0c3b077000bb9fa54894b670b047660 to your computer and use it in GitHub Desktop.
Save jasongorman/e0c3b077000bb9fa54894b670b047660 to your computer and use it in GitHub Desktop.
export function Clock() {
this.hours = 0;
this.mins = 0;
this.secs = 0;
this.observable = new Observable();
this.reset = () => {
this.hours = 0;
this.mins = 0;
this.secs = 0;
this.observable.notify();
}
this.tick = () => {
this.secs++;
if (this.secs == 60) {
this.secs = 0;
this.mins++;
}
if (this.mins == 60) {
this.mins = 0;
this.hours++;
}
this.observable.notify();
};
this.totalSeconds = () => {
return (this.hours * 60 * 60) + (this.mins * 60) + this.secs;
}
this.addObserver = (observer) => {
this.observable.addObserver(observer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment