Skip to content

Commit

Permalink
fix(slice): properly memoize loader selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Dec 14, 2023
1 parent 4ca821e commit 7a9702e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions store/slice/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ function loaderSelectors<
{ ids }: PropIds,
): LoaderState<M>[] =>
ids.map((id) => defaultLoader<M>(data[id])).filter(excludesFalse);
const selectById = (state: S, { id }: PropId): LoaderState<M> => {
const data = selectTable(state);
return defaultLoader<M>(findById(data, { id })) || empty;
};
const selectById = createSelector(
selectTable,
(_: S, p: PropId) => p.id,
(loaders, id): LoaderState<M> => findById(loaders, { id }),
);

return {
findById,
Expand All @@ -101,8 +102,8 @@ function loaderSelectors<
selectById,
selectByIds: createSelector(
selectTable,
(_: S, p: PropIds) => p,
findByIds,
(_: S, p: PropIds) => p.ids,
(loaders, ids) => findByIds(loaders, { ids }),
),
};
}
Expand Down

0 comments on commit 7a9702e

Please sign in to comment.