Default constructor
Closed this issue · 1 comments
In the README.md there is the statements:
In Redux, state is immutable, meaning that if it needs to be mutated a new state object is created. For that purpose, WeatherState does not expose setter of its properties, and doesn't not have a default constructor.
RootState itself is handled by a out of the box reducer and don't must have a default constructor.
First looking at both states it seems that even though an explicit default constructor is not defined there is an implicit default constructor. In other words with C# you can still do new RootState()
or new WeatherState()
? So is it desirable to explicily mark the default constructor with something like private RootState()
?
Second it seems like there is a grammar error. I don't know what is meant by
and don't must have
Or the double negative
and doesn't not have
Hi @KevinBurton, apologies for the confusion and grammar, I'll fix the readme shortly.
What that section meant to say is that the RootState class must have a default constructor and that rule is enforced by a constraint in AggregateReducer. For classes that represent state "slices", it is up to the developer how to define a ctor. BlazorState will not call default ctor or any ctor on the class representing state "slice". Right now It is a responsibility of the developer writing a reducer to ensure that in case of a change new instance is returned.