HaasStefan / ng-journal-comments

Comment repository containing all the comments as issues using utterances
2 stars 0 forks source link

https://ng-journal.com/blog/2023-08-09-nx-and-ngrx/ #4

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Architecting an Nx Workspace containing NgRx

NgRx is the most popular state management library for Angular. You find it a lot in enterprise projects. Nx is also used a lot in enterprise projects. So how do you architect an Nx Workspace with NgRx?

https://ng-journal.com/blog/2023-08-09-nx-and-ngrx/

acampon-sw commented 1 year ago

Hi Stefan, Thank you for all the great content that you make !!

A quick question, regarding ngrx with stand alone components: In your routes, inside "Customer" Domain, we have only one feature,"feature-list", but what about if we have another one like "feature-edit" ? Here the need of a top level reducer, to group the feature specific reducers would be required, because in big applications state would end being confused.

What im trying to achieve is the following model of my state: customers : { customers-list : // The state of your reducer customersFeatureList customer-edit : // A customerFeatureEdit }

With NgModules, what I used to do is use ActionReducerMap, and group all the internal states of my domain, but with this approach the problem is that when I load one feature of my domain, I will unecesarelly load all the other feature states.

Do you have any example, or can you help me achieve the described behaviour ?

Thank you in advance!!

HaasStefan commented 1 year ago

Hi @acampon-sw,

I usually keep all the state in the NgRx feature slice of a domain and do not separate based on features. I think that is totally fine as long as you keep a good action hygiene.

If you want to have some more local state that is only used in one feature, I would not put that into the NgRx store in the first place. For such a case, I can recommend the @ngrx/component-store, which is a local light-weight Redux-like store with the intention to manage the state of just one component.

Hope this helps!

timsar2 commented 11 months ago

I have problem to use ngrx-feature-store. After generating the files, Inside the product.reducer, there is not productFeature buy other methods and constant are exist.

nx g @nx/angular:ngrx-feature-store products --parent=libs/product/routes/src/lib/product.routes.ts --directory="../../../state/src/lib" --skipImport=true