react-redux-cache 0.13.0 → 0.14.0
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.
- package/README.md +1 -3
- package/dist/createActions.d.ts +8 -0
- package/dist/createActions.js +7 -0
- package/dist/createCache.d.ts +37 -27
- package/dist/createCache.js +8 -4
- package/dist/createCacheReducer.d.ts +2 -11
- package/dist/createCacheReducer.js +13 -11
- package/dist/index.js +2 -2
- package/dist/types.d.ts +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
# react-redux-cache (RRC)
|
|
11
11
|
|
|
12
|
-
**Powerful** yet **lightweight** data fetching and caching library that supports **normalization** unlike `
|
|
12
|
+
**Powerful** yet **lightweight** data fetching and caching library that supports **normalization** unlike `React Query` and `RTK-Query`, while having similar but not over-engineered, simple interface. Another advantage over `RTK-Query` is that it easily supports `Infinite Scroll`. Built on top of `Redux`, covered with tests, fully typed and written on Typescript.
|
|
13
13
|
|
|
14
14
|
**Normalization** is the best way to keep the state of the app **consistent** between different views, reduces the number of fetches and allows to show cached data when navigating, which greatly improves **user experience**.
|
|
15
15
|
|
|
@@ -200,7 +200,6 @@ const store = configureStore({
|
|
|
200
200
|
})
|
|
201
201
|
```
|
|
202
202
|
#### api.ts
|
|
203
|
-
Query result should be of type `QueryResponse`, mutation result should be of type `MutationResponse`.
|
|
204
203
|
For normalization `normalizr` package is used in this example, but any other tool can be used if query result is of proper type.
|
|
205
204
|
Perfect implementation is when the backend already returns normalized data.
|
|
206
205
|
```typescript
|
|
@@ -432,7 +431,6 @@ export const GetUsersScreen = () => {
|
|
|
432
431
|
const onLoadNextPage = () => {
|
|
433
432
|
const lastLoadedPage = usersResult?.page ?? 0
|
|
434
433
|
fetchUsers({
|
|
435
|
-
query: 'getUsers',
|
|
436
434
|
params: lastLoadedPage + 1,
|
|
437
435
|
})
|
|
438
436
|
}
|
package/dist/createActions.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EntityChanges, Key, MutationState, QueryState, Typenames } from './types';
|
|
2
|
+
import { ReduxCacheState } from './types';
|
|
2
3
|
export type Actions<N extends string = string, T extends Typenames = Typenames, QP = unknown, QR = unknown, MP = unknown, MR = unknown> = ReturnType<typeof createActions<N, T, QP, QR, MP, MR>>;
|
|
3
4
|
export declare const createActions: <N extends string, T extends Typenames, QP, QR, MP, MR>(name: N) => {
|
|
4
5
|
updateQueryStateAndEntities: {
|
|
@@ -72,4 +73,11 @@ export declare const createActions: <N extends string, T extends Typenames, QP,
|
|
|
72
73
|
};
|
|
73
74
|
type: `@rrc/${N}/clearMutationState`;
|
|
74
75
|
};
|
|
76
|
+
clearCache: {
|
|
77
|
+
(stateToKeep?: Partial<ReduxCacheState<T, QP, QR, MP, MR>>): {
|
|
78
|
+
type: `@rrc/${N}/clearCache`;
|
|
79
|
+
stateToKeep: Partial<ReduxCacheState<T, QP, QR, MP, MR>> | undefined;
|
|
80
|
+
};
|
|
81
|
+
type: `@rrc/${N}/clearCache`;
|
|
82
|
+
};
|
|
75
83
|
};
|
package/dist/createActions.js
CHANGED
|
@@ -45,6 +45,12 @@ const createActions = (name) => {
|
|
|
45
45
|
mutationKeys,
|
|
46
46
|
});
|
|
47
47
|
clearMutationState.type = clearMutationStateType;
|
|
48
|
+
const clearCacheType = `${actionPrefix}clearCache`;
|
|
49
|
+
const clearCache = (stateToKeep) => ({
|
|
50
|
+
type: clearCacheType,
|
|
51
|
+
stateToKeep,
|
|
52
|
+
});
|
|
53
|
+
clearCache.type = clearCacheType;
|
|
48
54
|
return {
|
|
49
55
|
updateQueryStateAndEntities,
|
|
50
56
|
updateMutationStateAndEntities,
|
|
@@ -52,6 +58,7 @@ const createActions = (name) => {
|
|
|
52
58
|
invalidateQuery,
|
|
53
59
|
clearQueryState,
|
|
54
60
|
clearMutationState,
|
|
61
|
+
clearCache,
|
|
55
62
|
};
|
|
56
63
|
};
|
|
57
64
|
exports.createActions = createActions;
|
package/dist/createCache.d.ts
CHANGED
|
@@ -17,11 +17,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
17
17
|
/** Keeps all options, passed while creating the cache. */
|
|
18
18
|
cache: Cache<N, T, QP, QR, MP, MR>;
|
|
19
19
|
/** Reducer of the cache, should be added to redux store. */
|
|
20
|
-
reducer: (state: {
|
|
21
|
-
entities: import("./types").EntitiesMap<T>;
|
|
22
|
-
queries: { [QK in keyof (QP | QR)]: import("./types").Dict<import("./types").QueryState<QP[QK], QR[QK]> | undefined>; };
|
|
23
|
-
mutations: { [MK in keyof (MP | MR)]: import("./types").MutationState<MP[MK], MR[MK]>; };
|
|
24
|
-
} | undefined, action: {
|
|
20
|
+
reducer: (state: import("./types").ReduxCacheState<T, QP, QR, MP, MR> | undefined, action: {
|
|
25
21
|
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
26
22
|
queryKey: keyof QP & keyof QR;
|
|
27
23
|
queryCacheKey: Key;
|
|
@@ -51,11 +47,10 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
51
47
|
} | {
|
|
52
48
|
type: `@rrc/${N}/clearMutationState`;
|
|
53
49
|
mutationKeys: (keyof MP & keyof MR)[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
50
|
+
} | {
|
|
51
|
+
type: `@rrc/${N}/clearCache`;
|
|
52
|
+
stateToKeep: Partial<import("./types").ReduxCacheState<T, QP, QR, MP, MR>> | undefined;
|
|
53
|
+
}) => import("./types").ReduxCacheState<T, QP, QR, MP, MR>;
|
|
59
54
|
actions: {
|
|
60
55
|
/** Updates query state, and optionally merges entity changes in a single action. */
|
|
61
56
|
updateQueryStateAndEntities: {
|
|
@@ -78,7 +73,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
78
73
|
};
|
|
79
74
|
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
80
75
|
};
|
|
81
|
-
/**
|
|
76
|
+
/** Merges EntityChanges to the state. */
|
|
82
77
|
mergeEntityChanges: {
|
|
83
78
|
(changes: import("./types").EntityChanges<T>): {
|
|
84
79
|
type: `@rrc/${N}/mergeEntityChanges`;
|
|
@@ -102,7 +97,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
102
97
|
};
|
|
103
98
|
type: `@rrc/${N}/invalidateQuery`;
|
|
104
99
|
};
|
|
105
|
-
/**
|
|
100
|
+
/** Clears states for provided query keys and cache keys.
|
|
106
101
|
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
107
102
|
clearQueryState: {
|
|
108
103
|
<K extends keyof QP & keyof QR>(queries: {
|
|
@@ -117,7 +112,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
117
112
|
};
|
|
118
113
|
type: `@rrc/${N}/clearQueryState`;
|
|
119
114
|
};
|
|
120
|
-
/**
|
|
115
|
+
/** Clears states for provided mutation keys. */
|
|
121
116
|
clearMutationState: {
|
|
122
117
|
<K extends keyof MP & keyof MR>(mutationKeys: K[]): {
|
|
123
118
|
type: `@rrc/${N}/clearMutationState`;
|
|
@@ -125,8 +120,18 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
|
125
120
|
};
|
|
126
121
|
type: `@rrc/${N}/clearMutationState`;
|
|
127
122
|
};
|
|
123
|
+
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
124
|
+
clearCache: {
|
|
125
|
+
(stateToKeep?: Partial<import("./types").ReduxCacheState<T, QP, QR, MP, MR>> | undefined): {
|
|
126
|
+
type: `@rrc/${N}/clearCache`;
|
|
127
|
+
stateToKeep: Partial<import("./types").ReduxCacheState<T, QP, QR, MP, MR>> | undefined;
|
|
128
|
+
};
|
|
129
|
+
type: `@rrc/${N}/clearCache`;
|
|
130
|
+
};
|
|
128
131
|
};
|
|
129
132
|
selectors: {
|
|
133
|
+
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
134
|
+
selectCacheState: (state: any) => import("./types").ReduxCacheState<T, QP, QR, MP, MR>;
|
|
130
135
|
/** Selects query state. */
|
|
131
136
|
selectQueryState: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => import("./types").QueryState<QK extends keyof QP & keyof QR ? QP[QK] : never, QK extends keyof QP & keyof QR ? QR[QK] : never>;
|
|
132
137
|
/** Selects query latest result. */
|
|
@@ -183,18 +188,14 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
183
188
|
queries: Partial<{ [QK in keyof (QP & QR)]: QK extends keyof QP & keyof QR ? import("./types").QueryInfo<N, Typenames, QP[QK], QR[QK], QP, QR, MP, MR> : never; }>;
|
|
184
189
|
mutations: Partial<{ [MK in keyof (MP & MR)]: MK extends keyof MP & keyof MR ? import("./types").MutationInfo<N, Typenames, MP[MK], MR[MK], QP, QR, MP, MR> : never; }>;
|
|
185
190
|
options: Partial<CacheOptions>;
|
|
186
|
-
cacheStateSelector: Partial<(state: any) => import("./
|
|
191
|
+
cacheStateSelector: Partial<(state: any) => import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>>;
|
|
187
192
|
}> & Omit<Omit<Cache<N, Typenames, QP, QR, MP, MR>, "globals">, "queries" | "mutations" | "options" | "cacheStateSelector"> & {
|
|
188
193
|
globals?: OptionalPartial<Globals<N, Typenames, QP, QR, MP, MR>, "queries"> | undefined;
|
|
189
194
|
}) => {
|
|
190
195
|
/** Keeps all options, passed while creating the cache. */
|
|
191
196
|
cache: Cache<N, Typenames, QP, QR, MP, MR>;
|
|
192
197
|
/** Reducer of the cache, should be added to redux store. */
|
|
193
|
-
reducer: (state: {
|
|
194
|
-
entities: import("./types").EntitiesMap<Typenames>;
|
|
195
|
-
queries: { [QK_1 in keyof (QP | QR)]: import("./types").Dict<import("./types").QueryState<QP[QK_1], QR[QK_1]> | undefined>; };
|
|
196
|
-
mutations: { [MK_1 in keyof (MP | MR)]: import("./types").MutationState<MP[MK_1], MR[MK_1]>; };
|
|
197
|
-
} | undefined, action: {
|
|
198
|
+
reducer: (state: import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR> | undefined, action: {
|
|
198
199
|
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
199
200
|
queryKey: keyof QP & keyof QR;
|
|
200
201
|
queryCacheKey: Key;
|
|
@@ -224,11 +225,10 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
224
225
|
} | {
|
|
225
226
|
type: `@rrc/${N}/clearMutationState`;
|
|
226
227
|
mutationKeys: (keyof MP & keyof MR)[];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
228
|
+
} | {
|
|
229
|
+
type: `@rrc/${N}/clearCache`;
|
|
230
|
+
stateToKeep: Partial<import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>> | undefined;
|
|
231
|
+
}) => import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>;
|
|
232
232
|
actions: {
|
|
233
233
|
/** Updates query state, and optionally merges entity changes in a single action. */
|
|
234
234
|
updateQueryStateAndEntities: {
|
|
@@ -251,7 +251,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
251
251
|
};
|
|
252
252
|
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
253
253
|
};
|
|
254
|
-
/**
|
|
254
|
+
/** Merges EntityChanges to the state. */
|
|
255
255
|
mergeEntityChanges: {
|
|
256
256
|
(changes: import("./types").EntityChanges<Typenames>): {
|
|
257
257
|
type: `@rrc/${N}/mergeEntityChanges`;
|
|
@@ -275,7 +275,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
275
275
|
};
|
|
276
276
|
type: `@rrc/${N}/invalidateQuery`;
|
|
277
277
|
};
|
|
278
|
-
/**
|
|
278
|
+
/** Clears states for provided query keys and cache keys.
|
|
279
279
|
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
280
280
|
clearQueryState: {
|
|
281
281
|
<K extends keyof QP & keyof QR>(queries: {
|
|
@@ -290,7 +290,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
290
290
|
};
|
|
291
291
|
type: `@rrc/${N}/clearQueryState`;
|
|
292
292
|
};
|
|
293
|
-
/**
|
|
293
|
+
/** Clears states for provided mutation keys. */
|
|
294
294
|
clearMutationState: {
|
|
295
295
|
<K extends keyof MP & keyof MR>(mutationKeys: K[]): {
|
|
296
296
|
type: `@rrc/${N}/clearMutationState`;
|
|
@@ -298,8 +298,18 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCach
|
|
|
298
298
|
};
|
|
299
299
|
type: `@rrc/${N}/clearMutationState`;
|
|
300
300
|
};
|
|
301
|
+
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
302
|
+
clearCache: {
|
|
303
|
+
(stateToKeep?: Partial<import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>> | undefined): {
|
|
304
|
+
type: `@rrc/${N}/clearCache`;
|
|
305
|
+
stateToKeep: Partial<import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>> | undefined;
|
|
306
|
+
};
|
|
307
|
+
type: `@rrc/${N}/clearCache`;
|
|
308
|
+
};
|
|
301
309
|
};
|
|
302
310
|
selectors: {
|
|
311
|
+
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
312
|
+
selectCacheState: (state: any) => import("./types").ReduxCacheState<Typenames, QP, QR, MP, MR>;
|
|
303
313
|
/** Selects query state. */
|
|
304
314
|
selectQueryState: <QK_1 extends keyof QP | keyof QR>(state: unknown, query: QK_1, cacheKey: Key) => import("./types").QueryState<QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never, QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>;
|
|
305
315
|
/** Selects query latest result. */
|
package/dist/createCache.js
CHANGED
|
@@ -53,7 +53,7 @@ const withTypenames = () => {
|
|
|
53
53
|
const { selectQueryState, selectQueryResult, selectQueryLoading, selectQueryError, selectQueryParams, selectQueryExpiresAt, selectMutationState, selectMutationResult, selectMutationLoading, selectMutationError, selectMutationParams, selectEntityById, selectEntities, selectEntitiesByTypename, } = selectors;
|
|
54
54
|
// actions
|
|
55
55
|
const actions = (0, createActions_1.createActions)(cache.name);
|
|
56
|
-
const { updateQueryStateAndEntities, updateMutationStateAndEntities, mergeEntityChanges, invalidateQuery, clearQueryState, clearMutationState, } = actions;
|
|
56
|
+
const { updateQueryStateAndEntities, updateMutationStateAndEntities, mergeEntityChanges, invalidateQuery, clearQueryState, clearMutationState, clearCache, } = actions;
|
|
57
57
|
return {
|
|
58
58
|
/** Keeps all options, passed while creating the cache. */
|
|
59
59
|
cache,
|
|
@@ -64,17 +64,21 @@ const withTypenames = () => {
|
|
|
64
64
|
updateQueryStateAndEntities,
|
|
65
65
|
/** Updates mutation state, and optionally merges entity changes in a single action. */
|
|
66
66
|
updateMutationStateAndEntities,
|
|
67
|
-
/**
|
|
67
|
+
/** Merges EntityChanges to the state. */
|
|
68
68
|
mergeEntityChanges,
|
|
69
69
|
/** Invalidates query states. */
|
|
70
70
|
invalidateQuery,
|
|
71
|
-
/**
|
|
71
|
+
/** Clears states for provided query keys and cache keys.
|
|
72
72
|
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
73
73
|
clearQueryState,
|
|
74
|
-
/**
|
|
74
|
+
/** Clears states for provided mutation keys. */
|
|
75
75
|
clearMutationState,
|
|
76
|
+
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
77
|
+
clearCache,
|
|
76
78
|
},
|
|
77
79
|
selectors: {
|
|
80
|
+
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
81
|
+
selectCacheState: cache.cacheStateSelector,
|
|
78
82
|
/** Selects query state. */
|
|
79
83
|
selectQueryState,
|
|
80
84
|
/** Selects query latest result. */
|
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import type { Actions } from './createActions';
|
|
2
|
-
import type { CacheOptions,
|
|
3
|
-
export
|
|
4
|
-
export declare const createCacheReducer: <N extends string, T extends Typenames, QP, QR, MP, MR>(actions: Actions<N, T, QP, QR, MP, MR>, queryKeys: (keyof (QP | QR))[], cacheOptions: CacheOptions) => (state: {
|
|
5
|
-
entities: EntitiesMap<T>;
|
|
6
|
-
queries: { [QK in keyof (QP | QR)]: Dict<QueryState<QP[QK], QR[QK]> | undefined>; };
|
|
7
|
-
mutations: { [MK in keyof (MP | MR)]: MutationState<MP[MK], MR[MK]>; };
|
|
8
|
-
} | undefined, action: ReturnType<(typeof actions)[keyof typeof actions]>) => {
|
|
9
|
-
entities: EntitiesMap<T>;
|
|
10
|
-
queries: { [QK in keyof (QP | QR)]: Dict<QueryState<QP[QK], QR[QK]> | undefined>; };
|
|
11
|
-
mutations: { [MK in keyof (MP | MR)]: MutationState<MP[MK], MR[MK]>; };
|
|
12
|
-
};
|
|
2
|
+
import type { CacheOptions, ReduxCacheState, Typenames } from './types';
|
|
3
|
+
export declare const createCacheReducer: <N extends string, T extends Typenames, QP, QR, MP, MR>(actions: Actions<N, T, QP, QR, MP, MR>, queryKeys: (keyof (QP | QR))[], cacheOptions: CacheOptions) => (state: ReduxCacheState<T, QP, QR, MP, MR> | undefined, action: ReturnType<(typeof actions)[keyof typeof actions]>) => ReduxCacheState<T, QP, QR, MP, MR>;
|
|
@@ -16,17 +16,14 @@ const utilsAndConstants_1 = require("./utilsAndConstants");
|
|
|
16
16
|
const optionalQueryKeys = ['error', 'expiresAt', 'result', 'params'];
|
|
17
17
|
const optionalMutationKeys = ['error', 'result', 'params'];
|
|
18
18
|
const createCacheReducer = (actions, queryKeys, cacheOptions) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
queries: queryStateMap,
|
|
28
|
-
mutations: mutationStateMap,
|
|
29
|
-
};
|
|
19
|
+
const initialState = Object.freeze({
|
|
20
|
+
entities: Object.freeze({}),
|
|
21
|
+
queries: Object.freeze(queryKeys.reduce((result, x) => {
|
|
22
|
+
result[x] = Object.freeze({});
|
|
23
|
+
return result;
|
|
24
|
+
}, {})),
|
|
25
|
+
mutations: Object.freeze({}),
|
|
26
|
+
});
|
|
30
27
|
cacheOptions.logsEnabled &&
|
|
31
28
|
(0, utilsAndConstants_1.log)('createCacheReducer', {
|
|
32
29
|
queryKeys,
|
|
@@ -205,6 +202,11 @@ const createCacheReducer = (actions, queryKeys, cacheOptions) => {
|
|
|
205
202
|
? state
|
|
206
203
|
: Object.assign(Object.assign({}, state), { mutations: newMutations });
|
|
207
204
|
}
|
|
205
|
+
case actions.clearCache.type: {
|
|
206
|
+
const { stateToKeep } = action;
|
|
207
|
+
return stateToKeep
|
|
208
|
+
? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState;
|
|
209
|
+
}
|
|
208
210
|
}
|
|
209
211
|
return state;
|
|
210
212
|
};
|
package/dist/index.js
CHANGED
|
@@ -27,12 +27,12 @@ Object.defineProperty(exports, "FetchPolicy", { enumerable: true, get: function
|
|
|
27
27
|
Object.defineProperty(exports, "isEmptyObject", { enumerable: true, get: function () { return utilsAndConstants_1.isEmptyObject; } });
|
|
28
28
|
// Backlog
|
|
29
29
|
// ! high (1.0.0-rc.0)
|
|
30
|
+
// reset [whole] cache to initial / to provided state
|
|
31
|
+
// optimistic response
|
|
30
32
|
// generate full api docs
|
|
31
33
|
// ! medium
|
|
32
|
-
// optimistic response
|
|
33
34
|
// onCancel & onAbort
|
|
34
35
|
// remove empty entities and queries from state
|
|
35
|
-
// reset [whole] cache to initial / to provided state
|
|
36
36
|
// globals for success, completions and loading states?
|
|
37
37
|
// make query key / cache key difference more clear in the docs
|
|
38
38
|
// check type of function arguments in dev
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Store } from 'redux';
|
|
2
2
|
import type { Actions } from './createActions';
|
|
3
|
-
import type { ReduxCacheState } from './createCacheReducer';
|
|
4
3
|
import type { Selectors } from './createSelectors';
|
|
5
4
|
export type Key = string | number | symbol;
|
|
6
5
|
export type Dict<T> = Record<Key, T>;
|
|
@@ -72,6 +71,15 @@ export type EntitiesMap<T extends Typenames> = {
|
|
|
72
71
|
export type EntityIds<T extends Typenames> = {
|
|
73
72
|
[K in keyof T]?: Key[];
|
|
74
73
|
};
|
|
74
|
+
export type ReduxCacheState<T extends Typenames, QP, QR, MP, MR> = {
|
|
75
|
+
entities: EntitiesMap<T>;
|
|
76
|
+
queries: {
|
|
77
|
+
[QK in keyof (QP | QR)]: Dict<QueryState<QP[QK], QR[QK]> | undefined>;
|
|
78
|
+
};
|
|
79
|
+
mutations: {
|
|
80
|
+
[MK in keyof (MP | MR)]: MutationState<MP[MK], MR[MK]>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
75
83
|
export type QueryInfo<N extends string, T extends Typenames = Typenames, P = unknown, R = unknown, QP = unknown, QR = unknown, MP = unknown, MR = unknown> = Partial<Pick<Globals<N, T, QP, QR, MP, MR>['queries'], 'skipFetch' | 'secondsToLive'>> & {
|
|
76
84
|
query: NormalizedQuery<T, P, R>;
|
|
77
85
|
/** Determines when useQuery fetch triggers should start fetching. Fetch is performed if function returns true.
|
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.
|
|
5
|
+
"version": "0.14.0",
|
|
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",
|