Created
June 16, 2016 07:46
-
-
Save Janiczek/fdee27d10e933f1d4f948807559c8255 to your computer and use it in GitHub Desktop.
MobX store
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
class Store { | |
/********************************** | |
* BASE VALUES | |
**********************************/ | |
@observable bpm = 120; | |
@observable playing = false; | |
/********************************** | |
* COMPUTED VALUES | |
**********************************/ | |
@computed get msPerClick() { | |
return 60000 / this.bpm; | |
} | |
@computed get playButtonIcon() { | |
return this.playing ? 'stop' : 'play'; | |
} | |
@computed get bpmString() { | |
return (this.bpm) ? this.bpm.toString() : ''; | |
} | |
/********************************** | |
* ACTIONS | |
**********************************/ | |
@action togglePlaying() { | |
this.playing = !this.playing; | |
} | |
@action setBpmFromString(bpmString) { | |
this.bpm = parseFloat(bpmString) || null; | |
} | |
@action clampBpm() { | |
this.bpm = clamp(this.bpm, 1, 999.999); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment