angularngrxngrx-store-4.0

How to use the methods pop() or shift() inside of an ngrx selector?


Hi in my redux store a carerequest has one or more appointments, i am working with a list of carerequests where the first time a carerequest is rendered it should pick the first appointment and the second time the second appointment but we can't use pop or shift inside of our selector does anyone know a work around or how we should use pop() or shift() inside of an ngrx selector or could we dispatch an action inside of our selector?


Solution

  • pop() and shift() are mutable functions. And the state of the store should be read-only.

    You can imagine something like this:

    export const selectFilteredRequests = createSelector(
      selectRequests,
      (requests: Request[]) => {
         const result = [...requests];
         result.pop() // Or result.shift()
         return result
      }
    );