(redux / ngrx) Would you recommend storing UI related states?

As far as I understand the principle of redux architecture, it eases the complexity when the application state changes (business logic?).

But is it also necessary to handle view-related states in a shorthand way? For example. whether the sidebar is currently open, or a specific block of information is unlocked, etc.?

This was done on the ngrx / store page . But since the application logic does not depend in any way on these view states, I cannot really see its benefits.

+3


source to share


3 answers


Each developer must decide which is according to the requirements of their application. In the sample app, the sidenav state is really not up to date as you specified correctly, so it is kept mostly for demo purposes.



+2


source


I had to do this for several reasons (this is more specific to the HTTP request loading status, error status, etc.):



  • Unable to determine status, success or http error . When we submit, post or upload a request, it is just a one-way flow. This will not give us if the request is successful or if it gave an error. Imagine the submit request gave a validation error, we need to save this

  • Less code in a component , easy to write unit tests, easy to code, easy to automate code. Services are always easy to test against components.

  • Update in multiple components . Imagine we are showing a summary in a dashboard and the actual data in a component. We need to show in the dashboard that the data is being updated, it is impossible if the status is stored in the component

  • Save application state to localstorage . One scenario I had to save the UI status to local storage. Sidebar users' preference increased or decreased, text size, etc. Even in these cases, the store had to be used.
+1


source


I agree that this will really depend on your requirements, but we can, however, consider some common cases, such as managing notifications (to display one notification at a time), user connection (many functions may have a specific user interface depending on this ) etc.

+1


source







All Articles