Created
April 7, 2021 22:36
-
-
Save aqrojo/d11ced61b4bf3de294e8c8763315157b to your computer and use it in GitHub Desktop.
mobx-introduction_01_observables
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
| import { observable } from 'mobx' | |
| function getThermomether (initialValue) { | |
| const thermometer = observable({ | |
| // model | |
| id: initialValue.id, | |
| celsius: initialValue.celsius, | |
| // actions | |
| setCelsius (val) { | |
| thermometer.celsius = val | |
| }, | |
| setFarenheith (val) { | |
| thermometer.celsius = (val - 32) * (5/9) | |
| }, | |
| // views | |
| get farenheith () { | |
| return (thermometer.celsius * (9/5)) + 32 | |
| }, | |
| get kelvin () { | |
| return (kelvinFormula) | |
| } | |
| }) | |
| return thermomether | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.