GuillaumeSalles / redux.NET

Redux.NET is a predictable state container for .NET apps. Inspired by https://github.com/reactjs/redux.
712 stars 86 forks source link

Action properties and grouping question #44

Closed johnmurphy01 closed 7 years ago

johnmurphy01 commented 7 years ago

In my project, I am using an action for each individual property within my application state. This is working just fine but I keep coming back to the question, "Should I be grouping my state properties within a single action?". For example, I have a login screen. Should I have one action that is the SetLoginStateAction that contains things such as whether the email is valid, the password, etc...? Or should I have a EmailValidAction, PasswordValidAction and so on? From a technical perspective, I understand that either one should work. I'm more looking for structure preferences.

GuillaumeSalles commented 7 years ago

Hi @johnmurphy01,

Good question! Here is a quote of the redux (Javascript) author on this subject : "[...] Redux is fairly useless if you treat actions as setters and couple actions directly to reducers." (https://twitter.com/dan_abramov/status/793379336309071872)

An action does not have to update a single property of your state. It does not have to be handled by a single reducer. An action can represent what a user would do in your app. For example, a "SignOutAction" could reset different parts of the application state. Personally, I find it better to have a "SignOutAction" instead of multiple "ResetStateXAction" because it help me to reason about of the application flow. (And it remove some boilerplate.)

You will find more info about structure here : http://redux.js.org/docs/recipes/StructuringReducers.html. This doc is about the original redux version but the idea stay the same.

Hope it helps!