Last active
October 2, 2019 12:30
-
-
Save alonbardavid/10617bd5601829978841997a1cba6b23 to your computer and use it in GitHub Desktop.
Patterns for deriving state gist10
This file contains hidden or 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 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