Last active
April 8, 2021 09:42
-
-
Save aqrojo/6121ac9ff195c3b10564e8c472f88a89 to your computer and use it in GitHub Desktop.
mobx-introduction_MST_1
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 { types } from 'mobx-state-tree' | |
// definición de un modelo mobx-state-tree | |
const ThermometerModel = types | |
.model({ | |
id: types.string, | |
celsius: types.number | |
}) | |
.actions (state => ({ | |
setCelsius (val) { | |
state.celsius = val | |
}, | |
... | |
})) | |
.views (state => ({ | |
get farenheight () { | |
return (state.celsius * (9/5)) + 32 | |
}, | |
... | |
})) | |
export default ThermometerModel | |
// instanciar un store | |
const thermomether = ThermometerModel.create({ | |
id: 't1', | |
celsius: 33 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como crear un manager para este modelo:
https://gist.github.com/aqrojo/d2f7e6001137f0551e0b33d79a3dc7b2