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 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 | |
} |
Author
aqrojo
commented
Apr 7, 2021
•
- Siempre contiene un modelo de datos
- Para modificar estos modelo vamos a usar acciones
- Puede además incluir vistas, para obtener valores derivados del estado
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment