forked from mobxjs/mobx
-
Notifications
You must be signed in to change notification settings - Fork 0
Language Support
Kevin Malakoff edited this page Feb 29, 2016
·
3 revisions
MobX supports ES5, ES6, and Typescript. Let's compare the README example in each language to understand how to use MobX in your language ecosystem of choice.
This is a great example of how using the latest JavaScript features help reduce boilerplate and increase code readability.
import {observable} from 'mobx';
class Todo {
id = Math.random();
@observable title = "";
@observable finished = false;
}
Instance fields and decorators can can be enabled in Babel via the transform-class-properties and transform-decorators-legacy plugin.
Using standard ES6 requires more explicit initialization.
import {extendObservable} from 'mobx';
class Todo {
constructor() {
this.id = Math.random();
extendObservable(this, {
title: "",
finished: false
});
}
}
Using standard ES5 requires a bit more boilerplate to create a class.
var m = require('mobx');
var Todo = function() {
this.id = Math.random();
m.extendObservable(this, {
title: "",
finished: false
});
}