Make class properties observable using decorators
import observable from 'observable-decorators';
class Person {
constructor(override) {
Object.assign(this, override);
}
@observable
first = 'Kevin';
@observable
last = 'Phillips';
@observable
get fullName() {
return this.first.combineLatest(this.last, (first, last) => {
return first + ' ' + last;
});
}
}
const person = new Person({
first: 'Kevin'
});
person.fullName.subscribe((fullName) => {
// 'Kevin Phillips',
// 'Kevin McCallister'
});
person.last = 'McCallister';