Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created June 16, 2016 07:46
Show Gist options
  • Save Janiczek/fdee27d10e933f1d4f948807559c8255 to your computer and use it in GitHub Desktop.
Save Janiczek/fdee27d10e933f1d4f948807559c8255 to your computer and use it in GitHub Desktop.
MobX store
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