ngrx/store createSelector with transient argument(s)

444 Views Asked by At

I'm creating selectors for @ngrx/store. Conceptually they seem to be akin to a stored procedure or something in SQL.

That said, I've got a need to provide arguments in some cases and this is the best solution I've arrived at so far.

const itemsAll = createSelector(state, (state) => state.items);

const itemById = (id) => createSelector(itemsAll, (items) => find(items, { Id: id }))

I know this example is pretty trivial, but what I'm trying to understand is how the itemById implementation impacts memoization. My intuition is telling me that it will break, and possibly even leak (in that each function returned by the factory will have its own cache that may never get released)?

That said, lord knows my intuition is not always correct... if anyone can provide some insight that would be amazing.

0

There are 0 best solutions below