@livestore/react 0.3.0-dev.19 → 0.3.0-dev.22

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/src/useQuery.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { GetResult, LiveQuery, LiveQueryDef, LiveQueryDefAny, RcRef, Store } from '@livestore/livestore'
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 LiveQueryDefAny>(
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 LiveQueryDefAny> =
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 LiveQueryDefAny>(
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