mr__brainwash
mr__brainwash

Reputation: 1382

Where to keep static data in the app (angular 5 and ngrx/store)?

We have complex app which is using angular 5 and ngrx/store. So my question is in the title, where we can keep some static data?

For example, it can be the list of genres of films. We need it sometimes to sort some other data and etc. It is not changeable data, we just get it once from the server when the user first load app. I don't see any reasons to keep it with changeable data in the store.

I see such solution: create shared reducer which will be available in every module of the app and it will keep all static data of the app. Is it good solution? Could you share with me better solution? Thanks!

Upvotes: 0

Views: 1757

Answers (1)

JeB
JeB

Reputation: 12133

One of the possible solutions is a service (@Injectable()).
You make a service which makes an Http call to the server and return an Observable of your data (preferably with publishReplay so that the new subscribers won't trigger the Http request again).

On one hand it won't be in the store but on the other hand you still continue working with Observables (which is a very handy thing in Angular).

However, I would stick with the store, because the whole point of Redux is a single place for all the application data.
It is easier to debug, easier to maintain and hey, no one said that tomorrow your immutable data won't become mutable.

Your solution with a single reducer for all the static data is not the solution I would go with, because it breaks modularity. Especially with new ngrx that support Features you want your store to be modular - to keep logically different pieces of data in separate modules.

Upvotes: 2

Related Questions