export default class AppComponent implements OnInit {
@HmrState() state = {
counter: 1
};
// when object's property is mutated, updated value is persisted
mutateInPlace() {
this.state.counter = this.state.counter + 1;
// at this point this.state.counter equals to 2; hmr works
}
// when variable is reassigned with new value (in favor of immutability), it's being discarded
assignNewInstance() {
this.state = {
counter: this.state.counter + 1;
};
// at this point this.state.counter is still 1; weird; hmr does not work
}
}
if (!currentValue) {
HmrStore._initialValues[key] = newValue;
} else {
newValue = Object.assign(newValue, currentValue); // << overwrites new value with old one??
}
return HmrStore.set(key, newValue);
Given component below:
Most likely the issue comes from HmrDecorator.ts.
I guess, it should have been as follows: