react-redux-cache 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,7 +87,7 @@ export declare const createCache: <N extends string, T extends Typenames, QP, QR
87
87
  mutationKeys: K_3[];
88
88
  };
89
89
  type: `@rrc/${N}/clearMutationState`;
90
- }; /** Selects query latest result. */
90
+ };
91
91
  };
92
92
  selectors: {
93
93
  /** Selects query state. */
@@ -107,7 +107,7 @@ export declare const createCache: <N extends string, T extends Typenames, QP, QR
107
107
  /** Selects mutation latest error. */
108
108
  selectMutationError: <MK_4 extends keyof MP | keyof MR>(state: unknown, mutation: MK_4) => Error | undefined;
109
109
  /** Selects entity by id and typename. */
110
- selectEntityById: <TN extends keyof T>(state: unknown, id: Key | null | undefined, typename: TN) => void;
110
+ selectEntityById: <TN extends keyof T>(state: unknown, id: Key | null | undefined, typename: TN) => T[TN] | undefined;
111
111
  /** Selects all entities. */
112
112
  selectEntities: (state: unknown) => import("./types").EntitiesMap<T>;
113
113
  /** Selects all entities of provided typename. */
@@ -128,6 +128,8 @@ export declare const createCache: <N extends string, T extends Typenames, QP, QR
128
128
  useMutation: <MK_6 extends keyof MP | keyof MR>(options: {
129
129
  mutation: MK_6;
130
130
  }) => readonly [(params: MK_6 extends keyof MP & keyof MR ? MP[MK_6] : never) => Promise<MutationResult<MK_6 extends infer T_2 ? T_2 extends MK_6 ? T_2 extends keyof MP & keyof MR ? MR[T_2] : never : never : never>>, QueryMutationState<MK_6 extends keyof MP & keyof MR ? MP[MK_6] : never>, () => boolean];
131
+ /** useSelector + selectEntityById. */
132
+ useSelectEntityById: <TN_2 extends keyof T>(id: Key | null | undefined, typename: TN_2) => T[TN_2] | undefined;
131
133
  };
132
134
  utils: {
133
135
  /**
@@ -29,6 +29,9 @@ const createCache = (partialCache) => {
29
29
  partialCache.abortControllers = abortControllers;
30
30
  const cache = partialCache;
31
31
  // make selectors
32
+ const selectEntityById = (state, id, typename) => {
33
+ return id == null ? undefined : cache.cacheStateSelector(state).entities[typename][id];
34
+ };
32
35
  const selectQueryState = (state, query, cacheKey) => {
33
36
  // @ts-expect-error fix later
34
37
  return cache.cacheStateSelector(state).queries[query][cacheKey];
@@ -77,9 +80,7 @@ const createCache = (partialCache) => {
77
80
  return selectMutationState(state, mutation).error;
78
81
  },
79
82
  /** Selects entity by id and typename. */
80
- selectEntityById: (state, id, typename) => {
81
- id == null ? undefined : cache.cacheStateSelector(state).entities[typename][id];
82
- },
83
+ selectEntityById,
83
84
  /** Selects all entities. */
84
85
  selectEntities: (state) => {
85
86
  return cache.cacheStateSelector(state).entities;
@@ -114,6 +115,10 @@ const createCache = (partialCache) => {
114
115
  useQuery: (options) => (0, useQuery_1.useQuery)(cache, actions, options),
115
116
  /** Subscribes to provided mutation state and provides mutate function. */
116
117
  useMutation: (options) => (0, useMutation_1.useMutation)(cache, actions, options, abortControllers),
118
+ /** useSelector + selectEntityById. */
119
+ useSelectEntityById: (id, typename) => {
120
+ return (0, react_redux_1.useSelector)((state) => selectEntityById(state, id, typename));
121
+ },
117
122
  },
118
123
  utils: {
119
124
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-redux-cache",
3
3
  "author": "Alexander Danilov",
4
4
  "license": "MIT",
5
- "version": "0.4.0",
5
+ "version": "0.4.2",
6
6
  "description": "Powerful data fetching and caching library that supports normalization, built on top of redux",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",