Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Last active October 2, 2019 12:30
Show Gist options
  • Save alonbardavid/10617bd5601829978841997a1cba6b23 to your computer and use it in GitHub Desktop.
Save alonbardavid/10617bd5601829978841997a1cba6b23 to your computer and use it in GitHub Desktop.
Patterns for deriving state gist10
class TimeRangeStore {
@observable
days;
constructor(days){
this.days = days;
}
@computed
get formatted(){
const {days} = this;
return days > 14? `${Math.floor(days / 7)} weeks`:days>1?`${days} days`:'1 day'
}
@action
set formatted(value){
const [count,unit] = value.split(" ");
const days = unit === "weeks"? count * 7: count;
this.days = days;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment