Created
April 28, 2019 08:21
-
-
Save jasongorman/e0c3b077000bb9fa54894b670b047660 to your computer and use it in GitHub Desktop.
This file contains 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
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