qortex-react 0.2.7 → 0.2.9

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/index.d.ts CHANGED
@@ -21,4 +21,25 @@ declare function useQueryData<F extends Fetcher>(key: QueryKey, opts: QueryOptio
21
21
  }): InferFetcherResult<F> | undefined;
22
22
  declare function useQueryData<T = any>(key: QueryKey, opts?: QueryOptions<T>): T | undefined;
23
23
 
24
- export { useQuery, useQueryData };
24
+ /**
25
+ * useQuerySelect hook for React integration with qortex
26
+ * Provides reactive data fetching with automatic re-renders on state changes
27
+ * Enhanced with automatic type inference from fetchers
28
+ *
29
+ * Now includes smart subscription: automatically detects which properties are accessed
30
+ * and only re-renders when those specific properties change, not the entire state.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * const query = useQuerySelect('users', { fetcher: fetchUsers });
35
+ *
36
+ * // Only re-renders when data or isSuccess changes, not when isError changes
37
+ * return <div>{query.isSuccess ? query.data?.name : 'Loading...'}</div>;
38
+ * ```
39
+ */
40
+ declare function useQuerySelect<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
41
+ fetcher: F;
42
+ }): QueryState<InferFetcherResult<F>>;
43
+ declare function useQuerySelect<T = any>(key: QueryKey, opts?: QueryOptions<T>): QueryState<T>;
44
+
45
+ export { useQuery, useQueryData, useQuerySelect };
package/index.js CHANGED
@@ -3,10 +3,11 @@
3
3
  var qortexCore = require('qortex-core');
4
4
  var react = require('react');
5
5
 
6
- function O(e,t){let r=qortexCore.serializeKey(e),u=react.useCallback(()=>qortexCore.getQueryState(e,t),[r]),n=react.useCallback(s=>qortexCore.subscribeQuery(e,s,t),[r]);return react.useSyncExternalStore(n,u)}function C(e,t){let r=qortexCore.serializeKey(e),u=react.useCallback(()=>qortexCore.getQueryData(e,t),[r]),n=react.useCallback(s=>qortexCore.subscribeQuery(e,s,t),[r]);return react.useSyncExternalStore(n,u)}
6
+ function A(e,t){let r=qortexCore.serializeKey(e),u=react.useCallback(()=>qortexCore.getQueryState(e,t),[r]),n=react.useCallback(o=>qortexCore.subscribeQuery(e,o,t),[r]);return react.useSyncExternalStore(n,u)}function V(e,t){let r=qortexCore.serializeKey(e),u=react.useCallback(()=>qortexCore.getQueryData(e,t),[r]),n=react.useCallback(o=>qortexCore.subscribeQuery(e,o,t),[r]);return react.useSyncExternalStore(n,u)}function re(e,t){let r=qortexCore.serializeKey(e),u=react.useRef(),n=react.useRef(new Set),a=react.useCallback(y=>qortexCore.subscribeQuery(e,s=>{let F=u.current,i=n.current;if(i.size===0){u.current=s,y();return}let Q=!1;for(let f of i)if(F?.[f]!==s[f]){Q=!0;break}Q&&(u.current=s,y());},t),[r]),o=react.useCallback(()=>qortexCore.getQueryState(e,t),[r]),c=react.useSyncExternalStore(a,o);return react.useMemo(()=>new Proxy(c,{get(y,s){return n.current.add(s),y[s]}}),[c])}
7
7
 
8
- exports.useQuery = O;
9
- exports.useQueryData = C;
8
+ exports.useQuery = A;
9
+ exports.useQueryData = V;
10
+ exports.useQuerySelect = re;
10
11
  Object.keys(qortexCore).forEach(function (k) {
11
12
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
12
13
  enumerable: true,
package/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { serializeKey, getQueryState, subscribeQuery, getQueryData } from 'qortex-core';
2
2
  export * from 'qortex-core';
3
- import { useCallback, useSyncExternalStore } from 'react';
3
+ import { useCallback, useSyncExternalStore, useRef, useMemo } from 'react';
4
4
 
5
- function O(e,t){let r=serializeKey(e),u=useCallback(()=>getQueryState(e,t),[r]),n=useCallback(s=>subscribeQuery(e,s,t),[r]);return useSyncExternalStore(n,u)}function C(e,t){let r=serializeKey(e),u=useCallback(()=>getQueryData(e,t),[r]),n=useCallback(s=>subscribeQuery(e,s,t),[r]);return useSyncExternalStore(n,u)}
5
+ function A(e,t){let r=serializeKey(e),u=useCallback(()=>getQueryState(e,t),[r]),n=useCallback(o=>subscribeQuery(e,o,t),[r]);return useSyncExternalStore(n,u)}function V(e,t){let r=serializeKey(e),u=useCallback(()=>getQueryData(e,t),[r]),n=useCallback(o=>subscribeQuery(e,o,t),[r]);return useSyncExternalStore(n,u)}function re(e,t){let r=serializeKey(e),u=useRef(),n=useRef(new Set),a=useCallback(y=>subscribeQuery(e,s=>{let F=u.current,i=n.current;if(i.size===0){u.current=s,y();return}let Q=!1;for(let f of i)if(F?.[f]!==s[f]){Q=!0;break}Q&&(u.current=s,y());},t),[r]),o=useCallback(()=>getQueryState(e,t),[r]),c=useSyncExternalStore(a,o);return useMemo(()=>new Proxy(c,{get(y,s){return n.current.add(s),y[s]}}),[c])}
6
6
 
7
- export { O as useQuery, C as useQueryData };
7
+ export { A as useQuery, V as useQueryData, re as useQuerySelect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qortex-react",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "React hook bridge for qortex runtime",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -26,7 +26,7 @@
26
26
  "type": "git",
27
27
  "url": "git+https://github.com/Darshan-Naik/qortex.git"
28
28
  },
29
- "homepage": "https://github.com/Darshan-Naik/qortex#readme",
29
+ "homepage": "https://qortex.darshannaik.com",
30
30
  "bugs": {
31
31
  "url": "https://github.com/Darshan-Naik/qortex/issues"
32
32
  },
@@ -40,9 +40,9 @@
40
40
  "typescript"
41
41
  ],
42
42
  "author": "Darshan Naik",
43
- "license": "MIT",
43
+ "license": "LGPL-3.0",
44
44
  "dependencies": {
45
- "qortex-core": "0.2.7"
45
+ "qortex-core": "0.2.9"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=18"