Example:
export class MaybeValue<T> {
@observable
public value: T;
public hasValue: boolean;
constructor(value: T) {
this.value = value;
this.hasValue = this.value != null;
}
public valueChanged() {
this.hasValue = this.value != null;
}
}
const boo = new MaybeValue<string>("hello");
console.log(JSON.stringify(boo)); // {"hasValue":true}
Crappy, super annoying workaround:
export class MaybeValue<T> {
public value: T;
public hasValue: boolean;
constructor(value: T) {
this.value = value;
this.hasValue = this.value != null;
}
public setValue(val: T){
this.value = val;
this.valueChanged();
}
public valueChanged() {
this.hasValue = this.value != null;
}
}
const boo = new MaybeValue<string>("hello");
console.log(JSON.stringify(boo)); // {"hasValue":true, "value": "hello"}
Any way to “just” make it work?