Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Last active March 12, 2018 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweststrate/6daf9eee8a10d8929937c0237890bca1 to your computer and use it in GitHub Desktop.
Save mweststrate/6daf9eee8a10d8929937c0237890bca1 to your computer and use it in GitHub Desktop.
Decorators in MobX
import { decorate, observable, flow } from "mobx"
/**
with decorator syntax enabled
*/
class City {
@observable location
@observable temperature
@action.bound
fetchTemperature () {
/* implementation */
}
}
/**
without decorator syntax enabled
*/
class City {
location
temperature
fetchTemperature () {
/* implementation */
}
}
decorate(City, {
location: observable,
temperature: observable,
fetchTemperature: action.bound
})
@themre
Copy link

themre commented Mar 12, 2018

missing action in the import? thanks otherwise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment