react-redux-cache 0.19.1 → 0.19.3

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 CHANGED
@@ -11,13 +11,31 @@
11
11
 
12
12
  ### Supports both `Redux` and `Zustand` (check /example)
13
13
 
14
- **Powerful**, **performant** 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 **doesn't use Immer** ([perf issue](https://github.com/reduxjs/redux-toolkit/issues/4793)). Covered with tests, fully typed and written on Typescript.
15
-
16
- **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**.
17
-
18
- Can be considered as `ApolloClient` for protocols other than `GraphQL`, but with **full control** over its storage - redux or zustand store, with ability to write custom selectors, actions and reducers to manage cached state.
19
-
20
- Examples of states, generated by cache reducer from `/example` project:
14
+ **Powerful**, **performant** 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. Covered with tests, fully typed and written on Typescript.
15
+
16
+ Can be considered as `ApolloClient` for protocols other than `GraphQL`, but with **full control** over its store - redux or zustand.
17
+
18
+ |Principle|Description|
19
+ |--|--|
20
+ |Full access to the store|You choose the store (redux / zustand) and have full access to state, reducer, actions, hooks, selectors and utils, used by this library, and can create your own.|
21
+ |Supports all kinds of queries / mutations|REST, GraphQL, databases - any async operations can be cached.|
22
+ |Fully typed|Written on TypeScript, everything is checked by compiler.|
23
+ |Not overengineered|Simplicity is the main goal.|
24
+ |Performance|Every function is heavily optimized, Immer is not used ([RTK [Query] issue](https://github.com/reduxjs/redux-toolkit/issues/4793)).|
25
+ |Reliability|High test coverage, zero issue policy.|
26
+ |Lightweight|`npx minified-size dist/*.js`<br/>minified: 22.9 kB<br/>gzipped: 9.06 kB<br/>brotlied: 8.07 kB|
27
+
28
+ |Feature|Description|
29
+ |--|--|
30
+ |De-duplication of queries / mutations|Similar parallel queries are combined into one, mutations - aborted.|
31
+ |Time to live & Invalidation|Choose how long query result can be used before expired, or clear / invalidate it manually.|
32
+ |Deep comparison|Rendering is much heavier than deep comparison of incoming data, so it is enabled by default to prevent excess renders.|
33
+ |Infinite pagination|Easily implemented - one or two direction.|
34
+ |Error handling|No need to use try / catch, errors are returned by fuctions and / or can be handled globally from single place.|
35
+ |Fetch policies|Decide if data is full enough or need to be fetched.|
36
+ |Normalization|Consistent state accross the app - better UX, minimum loading states and lower traffic consumption.|
37
+
38
+ #### Examples of states, generated by cache reducer from `/example` project:
21
39
  <details>
22
40
  <summary>
23
41
  Normalized
@@ -36,15 +36,22 @@ const withTypenames = () => {
36
36
  (_f = (_r = partialCache.globals).queries) !== null && _f !== void 0 ? _f : (_r.queries = {});
37
37
  (_g = (_s = partialCache.globals.queries).fetchPolicy) !== null && _g !== void 0 ? _g : (_s.fetchPolicy = utilsAndConstants_1.FetchPolicy.NoCacheOrExpired);
38
38
  (_h = (_t = partialCache.globals.queries).skipFetch) !== null && _h !== void 0 ? _h : (_t.skipFetch = false);
39
- (_j = partialCache.storeHooks) !== null && _j !== void 0 ? _j : (partialCache.storeHooks = {
40
- useStore: require('react-redux').useStore,
41
- useSelector: require('react-redux').useSelector,
42
- });
43
- (_k = partialCache.cacheStateSelector) !== null && _k !== void 0 ? _k : (partialCache.cacheStateSelector = (state) => state[cache.name]);
44
- (_l = partialCache.mutations) !== null && _l !== void 0 ? _l : (partialCache.mutations = {});
45
- (_m = partialCache.queries) !== null && _m !== void 0 ? _m : (partialCache.queries = {});
39
+ (_j = partialCache.cacheStateSelector) !== null && _j !== void 0 ? _j : (partialCache.cacheStateSelector = (state) => state[cache.name]);
40
+ (_k = partialCache.mutations) !== null && _k !== void 0 ? _k : (partialCache.mutations = {});
41
+ (_l = partialCache.queries) !== null && _l !== void 0 ? _l : (partialCache.queries = {});
46
42
  // @ts-expect-error private field for testing
47
43
  partialCache.abortControllers = abortControllers;
44
+ // Try/catch just for bunders like metro to consider this as optional dependency
45
+ // eslint-disable-next-line no-useless-catch
46
+ try {
47
+ (_m = partialCache.storeHooks) !== null && _m !== void 0 ? _m : (partialCache.storeHooks = {
48
+ useStore: require('react-redux').useStore,
49
+ useSelector: require('react-redux').useSelector,
50
+ });
51
+ }
52
+ catch (e) {
53
+ throw e;
54
+ }
48
55
  const cache = partialCache;
49
56
  // Validate options
50
57
  if (cache.options.deepComparisonEnabled && !utilsAndConstants_1.optionalUtils.deepEqual) {
package/package.json CHANGED
@@ -2,16 +2,17 @@
2
2
  "name": "react-redux-cache",
3
3
  "author": "Alexander Danilov",
4
4
  "license": "MIT",
5
- "version": "0.19.1",
5
+ "version": "0.19.3",
6
6
  "description": "Powerful data fetching and caching library for Redux and Zustand that supports normalization.",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "scripts": {
10
- "example": "(cd example && yarn && yarn dev)",
10
+ "example": "(cd example && yarn --production && yarn dev)",
11
11
  "clean": "rm -rf dist",
12
12
  "lint": "yarn eslint src",
13
13
  "lint-fix": "yarn eslint --fix src",
14
- "build": "yarn clean && yarn lint && tsc && rm -rf dist/testing && rm -rf dist/__tests__",
14
+ "build": "yarn clean && yarn lint && tsc && rm -rf dist/testing && rm -rf dist/__tests__ && yarn size",
15
+ "size": "npx minified-size dist/*.js | grep 'total:' | sed -E 's/.*total: [^,]*, ([^,]*), ([^,]*), ([^,]*).*/<br\\/>minified: \\1<br\\/>gzipped: \\2<br\\/>brotlied: \\3/'",
15
16
  "test": "node node_modules/jest/bin/jest.js",
16
17
  "preminor-rc": "yarn build && npm version preminor --preid rc",
17
18
  "prepatch-rc": "yarn build && npm version prepatch --preid rc",
@@ -20,8 +21,8 @@
20
21
  },
21
22
  "peerDependencies": {
22
23
  "fast-deep-equal": "*",
23
- "react": "^16",
24
- "react-redux": "^4"
24
+ "react": ">=16",
25
+ "react-redux": ">=4"
25
26
  },
26
27
  "peerDependenciesMeta": {
27
28
  "fast-deep-equal": {
@@ -47,6 +48,7 @@
47
48
  "eslint-plugin-simple-import-sort": "10.0.0",
48
49
  "jest": "29.5.0",
49
50
  "jest-environment-jsdom": "29.7.0",
51
+ "minified-size": "4.0.0",
50
52
  "prettier": "2.8.8",
51
53
  "react": "18.2.0",
52
54
  "react-dom": "18.2.0",