Skip to content

Instantly share code, notes, and snippets.

@aqrojo
Created April 7, 2021 22:36
Show Gist options
  • Save aqrojo/d11ced61b4bf3de294e8c8763315157b to your computer and use it in GitHub Desktop.
Save aqrojo/d11ced61b4bf3de294e8c8763315157b to your computer and use it in GitHub Desktop.
mobx-introduction_01_observables
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
}
@aqrojo
Copy link
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