repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
7a9702e
parent
4ca821e
author
Eric Bower
date
2023-12-14 17:47:04 +0000 UTC
fix(slice): properly memoize loader selectors
1 files changed,  +7, -6
M store/slice/loader.ts
+7, -6
 1@@ -85,10 +85,11 @@ function loaderSelectors<
 2     { ids }: PropIds,
 3   ): LoaderState<M>[] =>
 4     ids.map((id) => defaultLoader<M>(data[id])).filter(excludesFalse);
 5-  const selectById = (state: S, { id }: PropId): LoaderState<M> => {
 6-    const data = selectTable(state);
 7-    return defaultLoader<M>(findById(data, { id })) || empty;
 8-  };
 9+  const selectById = createSelector(
10+    selectTable,
11+    (_: S, p: PropId) => p.id,
12+    (loaders, id): LoaderState<M> => findById(loaders, { id }),
13+  );
14 
15   return {
16     findById,
17@@ -101,8 +102,8 @@ function loaderSelectors<
18     selectById,
19     selectByIds: createSelector(
20       selectTable,
21-      (_: S, p: PropIds) => p,
22-      findByIds,
23+      (_: S, p: PropIds) => p.ids,
24+      (loaders, ids) => findByIds(loaders, { ids }),
25     ),
26   };
27 }