Closed uhfath closed 2 years ago
You definitely shouldn't be putting reducer code in actions. Actions are a statement of intent only, and state is only what the client believes is true.
Reducers should be a separate concern, that know what the implications are of the user's intent and changes what you now know to be true.
I get your point, thanks.
Recently stumbled on a case when I moved a static state reducer inside an action class which has a parametrized constructor. Here is a repro.
Based on a stock sample I've modified a
IncrementCounterAction
class like this:Two moments here:
Reducers
;The issue is that this action class gets registered in a DI container automatically. Perhaps because of a
RecuderMethod
attribute being used. When launched there is an exception:If I remove the static reducer from the action and put it back to a separate static class than everything works. Is this an intentional behavior?
The reducer is moved to an action class to simplify development process. When clicking an action in IDE it opens the action's code along with it's reducers. Of course one could simply move the reducers in another nested static private class like this:
It's a sort of a feasible workaround, but just a bit more code to write. Just wanted to make sure it's not a bug or something.
P.S. Tested on a 5.2.0