ye-olde-dev
ye-olde-dev

Reputation: 1298

Should derived data be the responsibility of the NGRX store?

Should derived data be the responsibility of the NGRX store through selectors or should it be defined on the component that will use it? For example, let's say you have an object with startTime, itemsCompleted, and itemsRemaining. A utility function calculates some other properties such as expectedLate, expectedOverage, etc. Should that take place inside a selector or locally on the component? Does it matter?

Upvotes: 1

Views: 196

Answers (1)

timdeschryver
timdeschryver

Reputation: 15505

Personally, I like to use selectors for derived data. A component just retrieves data from the store and displays it.

This imho makes selectors and components easier to test. Following this convention it's also easier for devs to find the information they are looking for.

Also, you have one single source of truth. For example, if a user logs out you just have to update the user instead of updating the user and setting a isLoggedIn flag to false.

Upvotes: 3

Related Questions