I'm building two widgets with mobx/react, where all the logic sits inside the stores. Both share most of the design rules, so their stores are 95% identical. Is there a smart way to handle this situation? For example, is it possible to create inheritance such as this?
class Animal {
@observable name = "";
constructor(name) {
this.name = name;
}
@computed get sentence() {
console.log(this.name + ' makes a noise.');
}
}
class Dog extends Animal {
@observable isBarking = false;
@computed get bark() {
if (this.isBarking){
console.log('The dog is barking');
}
}
@action
setIsBarking(isBarking) {
this.isBarking = isBarking;
}
}