@livestore/react 0.3.0-dev.19 → 0.3.0-dev.21
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/dist/.tsbuildinfo +1 -1
- package/dist/LiveStoreProvider.d.ts +11 -6
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +29 -9
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +2 -2
- package/dist/useAtom.d.ts +4 -3
- package/dist/useAtom.d.ts.map +1 -1
- package/dist/useAtom.js.map +1 -1
- package/dist/useQuery.d.ts +8 -7
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js.map +1 -1
- package/package.json +12 -11
- package/src/LiveStoreProvider.tsx +44 -18
- package/src/useAtom.ts +8 -4
- package/src/useQuery.ts +10 -9
package/src/useQuery.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiveQuery, LiveQueryDef, Store } from '@livestore/livestore'
|
|
2
2
|
import { extractStackInfoFromStackTrace, stackInfoToString } from '@livestore/livestore'
|
|
3
|
+
import type { LiveQueries } from '@livestore/livestore/internal'
|
|
3
4
|
import { deepEqual, indent } from '@livestore/utils'
|
|
4
5
|
import * as otel from '@opentelemetry/api'
|
|
5
6
|
import React from 'react'
|
|
@@ -20,17 +21,17 @@ import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInp
|
|
|
20
21
|
* }
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
export const useQuery = <TQuery extends
|
|
24
|
+
export const useQuery = <TQuery extends LiveQueryDef.Any>(
|
|
24
25
|
queryDef: TQuery,
|
|
25
26
|
options?: { store?: Store },
|
|
26
|
-
): GetResult<TQuery> => useQueryRef(queryDef, options).valueRef.current
|
|
27
|
+
): LiveQueries.GetResult<TQuery> => useQueryRef(queryDef, options).valueRef.current
|
|
27
28
|
|
|
28
|
-
type GetQueryInfo<TQuery extends
|
|
29
|
+
type GetQueryInfo<TQuery extends LiveQueryDef.Any> =
|
|
29
30
|
TQuery extends LiveQueryDef<infer _1, infer TQueryInfo> ? TQueryInfo : never
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
*/
|
|
33
|
-
export const useQueryRef = <TQuery extends
|
|
34
|
+
export const useQueryRef = <TQuery extends LiveQueryDef.Any>(
|
|
34
35
|
queryDef: TQuery,
|
|
35
36
|
options?: {
|
|
36
37
|
store?: Store
|
|
@@ -40,8 +41,8 @@ export const useQueryRef = <TQuery extends LiveQueryDefAny>(
|
|
|
40
41
|
otelSpanName?: string
|
|
41
42
|
},
|
|
42
43
|
): {
|
|
43
|
-
valueRef: React.RefObject<GetResult<TQuery>>
|
|
44
|
-
queryRcRef: RcRef<LiveQuery<GetResult<TQuery>, GetQueryInfo<TQuery>>>
|
|
44
|
+
valueRef: React.RefObject<LiveQueries.GetResult<TQuery>>
|
|
45
|
+
queryRcRef: LiveQueries.RcRef<LiveQuery<LiveQueries.GetResult<TQuery>, GetQueryInfo<TQuery>>>
|
|
45
46
|
} => {
|
|
46
47
|
const { store } = useStore({ store: options?.store })
|
|
47
48
|
|
|
@@ -76,7 +77,7 @@ export const useQueryRef = <TQuery extends LiveQueryDefAny>(
|
|
|
76
77
|
// which takes care of disposing the queryRcRef
|
|
77
78
|
() => {},
|
|
78
79
|
)
|
|
79
|
-
const query$ = queryRcRef.value as LiveQuery<GetResult<TQuery>, GetQueryInfo<TQuery>>
|
|
80
|
+
const query$ = queryRcRef.value as LiveQuery<LiveQueries.GetResult<TQuery>, GetQueryInfo<TQuery>>
|
|
80
81
|
|
|
81
82
|
React.useDebugValue(`LiveStore:useQuery:${query$.id}:${query$.label}`)
|
|
82
83
|
// console.debug(`LiveStore:useQuery:${query$.id}:${query$.label}`)
|
|
@@ -111,7 +112,7 @@ Stack trace:
|
|
|
111
112
|
}, [otelContext, query$, stackInfo])
|
|
112
113
|
|
|
113
114
|
// We know the query has a result by the time we use it; so we can synchronously populate a default state
|
|
114
|
-
const [valueRef, setValue] = useStateRefWithReactiveInput<GetResult<TQuery>>(initialResult)
|
|
115
|
+
const [valueRef, setValue] = useStateRefWithReactiveInput<LiveQueries.GetResult<TQuery>>(initialResult)
|
|
115
116
|
|
|
116
117
|
// TODO we probably need to change the order of `useEffect` calls, so we destroy the query at the end
|
|
117
118
|
// before calling the LS `onEffect` on it
|