Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mobx failure
const { observable, computed, decorate } = require('mobx');
class OrderLine {
constructor() {
this.price = 10;
this.amount = 1;
}
get total() {
return this.price * this.amount;
}
}
decorate(OrderLine, {
price: observable,
amount: observable,
total: computed
});
const orderLine = new OrderLine();
console.log(orderLine.amount, orderLine.price);
console.log(orderLine.total);
console.log(orderLine.amount, orderLine.price);
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const {
observable,
computed,
decorate
} = require('mobx');
class OrderLine {
constructor() {
_defineProperty(this, "price", 10);
_defineProperty(this, "amount", 1);
}
get total() {
return this.price * this.amount;
}
}
decorate(OrderLine, {
price: observable,
amount: observable,
total: computed
});
const orderLine = new OrderLine();
console.log(orderLine.amount, orderLine.price);
console.log(orderLine.total);
console.log(orderLine.amount, orderLine.price);
const { observable, computed, decorate } = require('mobx');
class OrderLine {
price = 10;
amount = 1;
get total() { return this.price * this.amount; }
}
decorate(OrderLine, {
price: observable,
amount: observable,
total: computed
})
const orderLine = new OrderLine();
console.log(orderLine.amount, orderLine.price);
console.log(orderLine.total);
console.log(orderLine.amount, orderLine.price);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.