Created
December 1, 2018 18:36
-
-
Save ChALkeR/523c7fd5d4efdfb469249c30b9ba26d6 to your computer and use it in GitHub Desktop.
Mobx failure
This file contains hidden or 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
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); |
This file contains hidden or 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
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); |
This file contains hidden or 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
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