@livestore/react 0.3.0-dev.9 → 0.3.1-dev.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/LICENSE +201 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/LiveStoreContext.d.ts +10 -4
- package/dist/LiveStoreContext.d.ts.map +1 -1
- package/dist/LiveStoreContext.js +1 -11
- package/dist/LiveStoreContext.js.map +1 -1
- package/dist/LiveStoreProvider.d.ts +29 -12
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +84 -55
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +80 -29
- package/dist/LiveStoreProvider.test.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +122 -556
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +71 -30
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.d.ts +2 -2
- package/dist/experimental/components/LiveList.d.ts.map +1 -1
- package/dist/experimental/components/LiveList.js +10 -6
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/mod.d.ts +4 -5
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -5
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts +61 -0
- package/dist/useClientDocument.d.ts.map +1 -0
- package/dist/useClientDocument.js +79 -0
- package/dist/useClientDocument.js.map +1 -0
- package/dist/useClientDocument.test.d.ts +2 -0
- package/dist/useClientDocument.test.d.ts.map +1 -0
- package/dist/useClientDocument.test.js +175 -0
- package/dist/useClientDocument.test.js.map +1 -0
- package/dist/useQuery.d.ts +25 -3
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +67 -47
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.d.ts +1 -1
- package/dist/useQuery.test.d.ts.map +1 -1
- package/dist/useQuery.test.js +86 -24
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useRcResource.d.ts +76 -0
- package/dist/useRcResource.d.ts.map +1 -0
- package/dist/useRcResource.js +152 -0
- package/dist/useRcResource.js.map +1 -0
- package/dist/useRcResource.test.d.ts +2 -0
- package/dist/useRcResource.test.d.ts.map +1 -0
- package/dist/useRcResource.test.js +122 -0
- package/dist/useRcResource.test.js.map +1 -0
- package/dist/useStore.d.ts +9 -0
- package/dist/useStore.d.ts.map +1 -0
- package/dist/useStore.js +28 -0
- package/dist/useStore.js.map +1 -0
- package/dist/utils/useStateRefWithReactiveInput.d.ts.map +1 -1
- package/package.json +20 -13
- package/src/LiveStoreContext.ts +11 -16
- package/src/LiveStoreProvider.test.tsx +176 -37
- package/src/LiveStoreProvider.tsx +156 -81
- package/src/__snapshots__/useClientDocument.test.tsx.snap +613 -0
- package/src/__snapshots__/useQuery.test.tsx.snap +2011 -0
- package/src/__tests__/fixture.tsx +74 -47
- package/src/experimental/components/LiveList.tsx +10 -7
- package/src/mod.ts +5 -6
- package/src/useClientDocument.test.tsx +306 -0
- package/src/useClientDocument.ts +157 -0
- package/src/useQuery.test.tsx +182 -71
- package/src/useQuery.ts +95 -58
- package/src/useRcResource.test.tsx +167 -0
- package/src/useRcResource.ts +182 -0
- package/src/useStore.ts +36 -0
- package/dist/useAtom.d.ts +0 -5
- package/dist/useAtom.d.ts.map +0 -1
- package/dist/useAtom.js +0 -38
- package/dist/useAtom.js.map +0 -1
- package/dist/useRow.d.ts +0 -50
- package/dist/useRow.d.ts.map +0 -1
- package/dist/useRow.js +0 -93
- package/dist/useRow.js.map +0 -1
- package/dist/useRow.test.d.ts +0 -2
- package/dist/useRow.test.d.ts.map +0 -1
- package/dist/useRow.test.js +0 -202
- package/dist/useRow.test.js.map +0 -1
- package/dist/useScopedQuery.d.ts +0 -33
- package/dist/useScopedQuery.d.ts.map +0 -1
- package/dist/useScopedQuery.js +0 -87
- package/dist/useScopedQuery.js.map +0 -1
- package/dist/useScopedQuery.test.d.ts +0 -2
- package/dist/useScopedQuery.test.d.ts.map +0 -1
- package/dist/useScopedQuery.test.js +0 -60
- package/dist/useScopedQuery.test.js.map +0 -1
- package/src/__snapshots__/useRow.test.tsx.snap +0 -360
- package/src/useAtom.ts +0 -52
- package/src/useRow.test.tsx +0 -344
- package/src/useRow.ts +0 -188
- package/src/useScopedQuery.test.tsx +0 -96
- package/src/useScopedQuery.ts +0 -143
- package/tsconfig.json +0 -20
- package/vitest.config.js +0 -17
@@ -0,0 +1,167 @@
|
|
1
|
+
import * as ReactTesting from '@testing-library/react'
|
2
|
+
import * as React from 'react'
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
4
|
+
|
5
|
+
import { __resetUseRcResourceCache, useRcResource } from './useRcResource.js'
|
6
|
+
|
7
|
+
describe.each([{ strictMode: true }, { strictMode: false }])('useRcResource (strictMode=%s)', ({ strictMode }) => {
|
8
|
+
beforeEach(() => {
|
9
|
+
__resetUseRcResourceCache()
|
10
|
+
})
|
11
|
+
|
12
|
+
const wrapper = strictMode ? React.StrictMode : React.Fragment
|
13
|
+
|
14
|
+
it('should create a stateful entity using make and call cleanup on unmount', () => {
|
15
|
+
const makeSpy = vi.fn(() => Symbol('statefulResource'))
|
16
|
+
const cleanupSpy = vi.fn()
|
17
|
+
|
18
|
+
const { result, unmount } = ReactTesting.renderHook(() => useRcResource('key-1', makeSpy, cleanupSpy), { wrapper })
|
19
|
+
|
20
|
+
expect(makeSpy).toHaveBeenCalledTimes(1)
|
21
|
+
expect(result.current).toBeDefined()
|
22
|
+
|
23
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(0)
|
24
|
+
unmount()
|
25
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(1)
|
26
|
+
})
|
27
|
+
|
28
|
+
it('should reuse the same entity when the key remains unchanged', () => {
|
29
|
+
const makeSpy = vi.fn(() => Symbol('statefulResource'))
|
30
|
+
const cleanupSpy = vi.fn()
|
31
|
+
|
32
|
+
const { result, rerender, unmount } = ReactTesting.renderHook(
|
33
|
+
({ key }) => useRcResource(key, makeSpy, cleanupSpy),
|
34
|
+
{ initialProps: { key: 'consistent-key' }, wrapper },
|
35
|
+
)
|
36
|
+
|
37
|
+
const instance1 = result.current
|
38
|
+
|
39
|
+
// Re-render with the same key
|
40
|
+
rerender({ key: 'consistent-key' })
|
41
|
+
const instance2 = result.current
|
42
|
+
|
43
|
+
expect(instance1).toBe(instance2)
|
44
|
+
expect(makeSpy).toHaveBeenCalledTimes(1)
|
45
|
+
|
46
|
+
unmount()
|
47
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(1)
|
48
|
+
})
|
49
|
+
|
50
|
+
it('should dispose the previous instance when the key changes', () => {
|
51
|
+
const makeSpy = vi.fn(() => Symbol('statefulResource'))
|
52
|
+
const cleanupSpy = vi.fn()
|
53
|
+
|
54
|
+
const { result, rerender, unmount } = ReactTesting.renderHook(
|
55
|
+
({ key }) => useRcResource(key, makeSpy, cleanupSpy),
|
56
|
+
{ initialProps: { key: 'a' }, wrapper },
|
57
|
+
)
|
58
|
+
|
59
|
+
const instanceA = result.current
|
60
|
+
|
61
|
+
// Change the key; this should trigger the disposal of the 'a' instance
|
62
|
+
rerender({ key: 'b' })
|
63
|
+
const instanceB = result.current
|
64
|
+
|
65
|
+
expect(instanceA).not.toBe(instanceB)
|
66
|
+
expect(makeSpy).toHaveBeenCalledTimes(2)
|
67
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(1)
|
68
|
+
|
69
|
+
unmount()
|
70
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(2)
|
71
|
+
})
|
72
|
+
|
73
|
+
it('should not dispose the entity until all consumers unmount', () => {
|
74
|
+
const makeSpy = vi.fn(() => Symbol('statefulResource'))
|
75
|
+
const cleanupSpy = vi.fn()
|
76
|
+
|
77
|
+
// Simulate two consumers using the same key independently.
|
78
|
+
const { unmount: unmount1 } = ReactTesting.renderHook(() => useRcResource('shared-key', makeSpy, cleanupSpy), {
|
79
|
+
wrapper,
|
80
|
+
})
|
81
|
+
const { unmount: unmount2, result } = ReactTesting.renderHook(
|
82
|
+
() => useRcResource('shared-key', makeSpy, cleanupSpy),
|
83
|
+
{
|
84
|
+
wrapper,
|
85
|
+
},
|
86
|
+
)
|
87
|
+
|
88
|
+
expect(result.current).toBeDefined()
|
89
|
+
expect(makeSpy).toHaveBeenCalledTimes(1)
|
90
|
+
|
91
|
+
// Unmount first consumer; the entity should remain active.
|
92
|
+
unmount1()
|
93
|
+
expect(cleanupSpy).not.toHaveBeenCalled()
|
94
|
+
|
95
|
+
// Unmount second consumer; now the entity is disposed.
|
96
|
+
unmount2()
|
97
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(1)
|
98
|
+
})
|
99
|
+
|
100
|
+
it('should handle rapid key changes correctly', () => {
|
101
|
+
const makeSpy = vi.fn(() => Symbol('statefulResource'))
|
102
|
+
const cleanupSpy = vi.fn()
|
103
|
+
|
104
|
+
const { rerender, unmount } = ReactTesting.renderHook(({ key }) => useRcResource(key, makeSpy, cleanupSpy), {
|
105
|
+
initialProps: { key: '1' },
|
106
|
+
wrapper,
|
107
|
+
})
|
108
|
+
|
109
|
+
// Rapid sequence of key changes.
|
110
|
+
rerender({ key: '2' })
|
111
|
+
rerender({ key: '3' })
|
112
|
+
|
113
|
+
// Expect three creations: one each for keys '1', '2', '3'
|
114
|
+
expect(makeSpy).toHaveBeenCalledTimes(3)
|
115
|
+
// Cleanup should have been triggered for key '1' and key '2'
|
116
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(2)
|
117
|
+
|
118
|
+
unmount()
|
119
|
+
// Unmounting the final consumer disposes the key '3' instance.
|
120
|
+
expect(cleanupSpy).toHaveBeenCalledTimes(3)
|
121
|
+
})
|
122
|
+
})
|
123
|
+
|
124
|
+
// This code was useful to better understand the hook behaviour with and without strict mode
|
125
|
+
// describe('debug', () => {
|
126
|
+
// const useStrictTest = (key: string) => {
|
127
|
+
// const id = React.useId()
|
128
|
+
// console.log(key, 'id', id)
|
129
|
+
|
130
|
+
// const x = React.useMemo(() => {
|
131
|
+
// console.log('useMemo', key)
|
132
|
+
// return 'hi' + key
|
133
|
+
// }, [key])
|
134
|
+
|
135
|
+
// React.useEffect(() => {
|
136
|
+
// console.log('useEffect', key)
|
137
|
+
// return () => {
|
138
|
+
// console.log('unmount', key)
|
139
|
+
// }
|
140
|
+
// }, [])
|
141
|
+
|
142
|
+
// return x
|
143
|
+
// }
|
144
|
+
|
145
|
+
// it('strict mode component', () => {
|
146
|
+
// console.log('strict mode component')
|
147
|
+
// const Root = () => {
|
148
|
+
// useStrictTest('a')
|
149
|
+
// return null
|
150
|
+
// }
|
151
|
+
// const { unmount } = ReactTesting.render(
|
152
|
+
// <React.StrictMode>
|
153
|
+
// <Root />
|
154
|
+
// </React.StrictMode>,
|
155
|
+
// )
|
156
|
+
|
157
|
+
// unmount()
|
158
|
+
// })
|
159
|
+
|
160
|
+
// it('strict mode hook', () => {
|
161
|
+
// console.log('strict mode hook')
|
162
|
+
// const wrapper: React.FC<{ children: React.ReactNode }> = React.StrictMode
|
163
|
+
// const { unmount } = ReactTesting.renderHook(() => useStrictTest('b'), { wrapper })
|
164
|
+
|
165
|
+
// unmount()
|
166
|
+
// })
|
167
|
+
// })
|
@@ -0,0 +1,182 @@
|
|
1
|
+
import * as React from 'react'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Creates a reference-counted resource object that is "stable" across React lifecycles.
|
5
|
+
*
|
6
|
+
* The hook is primarily intended for creating stateful objects or entities where:
|
7
|
+
* 1) reference identity is crucial (e.g. stateful objects, references, ...)
|
8
|
+
* and needed to persist across multiple component instances
|
9
|
+
* 2) the `create`/`dispose` functions might be effectful and can be called exactly once per key
|
10
|
+
*
|
11
|
+
* **Goals:**
|
12
|
+
* - Guarantee stable reference identity for stateful entities that are created via the `create` function.
|
13
|
+
* - Strong guarantees about the `create`/`dispose` calls (i.e. exactly one `create`/`dispose` call per key)
|
14
|
+
* - Ensure that such state is retained across component re-mounts, even in development environments like
|
15
|
+
* React Strict Mode or during Fast Refresh.
|
16
|
+
* - Automatically handle resource disposal by decrementing a reference count and disposing of the resource
|
17
|
+
* when no components are using it.
|
18
|
+
*
|
19
|
+
* **Behavior:**
|
20
|
+
* - On the first render with a specific key, the `create` function is invoked to create the stateful entity,
|
21
|
+
* and the resource is stored in a cache with a reference count set to 1.
|
22
|
+
* - If another component renders with the same key, the cached entity is reused and its reference count is incremented.
|
23
|
+
* - When a component renders with a new key, the previous key's reference count is decremented and, if it reaches zero,
|
24
|
+
* the `dispose` function is called for that resource.
|
25
|
+
* - Upon component unmount, the reference count is decremented, leading to disposal (via the `dispose` function)
|
26
|
+
* if the reference count drops to zero. An unmount is either detected via React's `useEffect` callback or
|
27
|
+
* in the useMemo hook when the key changes.
|
28
|
+
*
|
29
|
+
* Why this is needed in LiveStore:
|
30
|
+
* Let's first take a look at the "trivial implementation":
|
31
|
+
*
|
32
|
+
* ```ts
|
33
|
+
* const useSimpleResource = <T>(create: () => T, dispose: (resource: T) => void) => {
|
34
|
+
* const val = React.useMemo(() => create(), [create])
|
35
|
+
*
|
36
|
+
* React.useEffect(() => {
|
37
|
+
* return () => {
|
38
|
+
* dispose(val)
|
39
|
+
* }
|
40
|
+
* }, [dispose, val])
|
41
|
+
|
42
|
+
* return val
|
43
|
+
* }
|
44
|
+
* ```
|
45
|
+
*
|
46
|
+
* LiveStore uses this hook to create LiveQuery instances which are stateful and must not be leaked.
|
47
|
+
* The simple implementation above would leak the LiveQuery instance if the component is unmounted or props change.
|
48
|
+
*
|
49
|
+
* **Usage:**
|
50
|
+
* ```tsx
|
51
|
+
* // Create a stateful object instance for a unique key and share it between components.
|
52
|
+
* const statefulObject = useRcResource(
|
53
|
+
* 'stable-object-key',
|
54
|
+
* () => createObjectInstance(),
|
55
|
+
* (object) => object.dispose()
|
56
|
+
* );
|
57
|
+
* ```
|
58
|
+
*
|
59
|
+
* **Caveats:**
|
60
|
+
* - The `create` function is intentionally omitted from the dependency array in `useMemo` to prevent
|
61
|
+
* unintended re-creations of the stateful entity. Avoid closing over changing values within `create`
|
62
|
+
* or include them in the `key`.
|
63
|
+
* - Ensure that the `dispose` function is stable or properly memoized as its reference is used in a `useEffect`.
|
64
|
+
* - Although the caching mechanism prevents duplicate instance creation for the same key, the strategy
|
65
|
+
* can interact in unexpected ways with React’s development patterns. Please report any issues if encountered.
|
66
|
+
*
|
67
|
+
* @template T The type of the stateful entity managed by the hook.
|
68
|
+
* @param key A unique identifier for the stateful entity. A change in this key triggers a disposal of the previous resource.
|
69
|
+
* @param create Function to create the stateful entity when it does not exist in the cache.
|
70
|
+
* @param dispose Function to dispose of the stateful entity when it’s no longer needed. Needs to be stable.
|
71
|
+
* @param _options Optional. Additional options such as a debug print callback for logging purposes.
|
72
|
+
* @returns The stateful entity corresponding to the provided key.
|
73
|
+
*/
|
74
|
+
export const useRcResource = <T>(
|
75
|
+
key: string,
|
76
|
+
create: () => T,
|
77
|
+
dispose: (resource: NoInfer<T>) => void,
|
78
|
+
_options?: { debugPrint?: (resource: NoInfer<T>) => ReadonlyArray<any> },
|
79
|
+
): T => {
|
80
|
+
const keyRef = React.useRef<string | undefined>(undefined)
|
81
|
+
const didDisposeInMemo = React.useRef(false)
|
82
|
+
|
83
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
84
|
+
const resource = React.useMemo(() => {
|
85
|
+
// console.debug('useMemo', key)
|
86
|
+
if (didDisposeInMemo.current) {
|
87
|
+
// console.debug('useMemo', key, 'skip')
|
88
|
+
const cachedItem = cache.get(key)
|
89
|
+
if (cachedItem !== undefined && cachedItem._tag === 'active') {
|
90
|
+
return cachedItem.resource
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
// Check if the key has changed (or is undefined)
|
95
|
+
if (keyRef.current !== undefined && keyRef.current !== key) {
|
96
|
+
// If the key has changed, decrement the reference on the previous key
|
97
|
+
const previousKey = keyRef.current
|
98
|
+
const cachedItemForPreviousKey = cache.get(previousKey)
|
99
|
+
if (cachedItemForPreviousKey !== undefined && cachedItemForPreviousKey._tag === 'active') {
|
100
|
+
// previousKeyRef.current = previousKey
|
101
|
+
cachedItemForPreviousKey.rc--
|
102
|
+
|
103
|
+
// console.debug('useMemo', key, 'rc--', previousKey, cachedItemForPreviousKey.rc)
|
104
|
+
|
105
|
+
if (cachedItemForPreviousKey.rc === 0) {
|
106
|
+
// Clean up the stateful resource if no longer referenced
|
107
|
+
dispose(cachedItemForPreviousKey.resource)
|
108
|
+
cache.set(previousKey, { _tag: 'destroyed' })
|
109
|
+
didDisposeInMemo.current = true
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
const cachedItem = cache.get(key)
|
115
|
+
if (cachedItem !== undefined && cachedItem._tag === 'active') {
|
116
|
+
// In React Strict Mode, the `useMemo` hook is called multiple times,
|
117
|
+
// so we only increment the reference from the first call for this component.
|
118
|
+
cachedItem.rc++
|
119
|
+
// console.debug('rc++', cachedItem.rc, ...(_options?.debugPrint?.(cachedItem.resource) ?? []))
|
120
|
+
|
121
|
+
return cachedItem.resource
|
122
|
+
}
|
123
|
+
|
124
|
+
// Create a new stateful resource if not cached
|
125
|
+
const resource = create()
|
126
|
+
cache.set(key, { _tag: 'active', rc: 1, resource })
|
127
|
+
return resource
|
128
|
+
// Dependency is deliberately limited to `key` to avoid unintended re-creations.
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
130
|
+
}, [key])
|
131
|
+
|
132
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
133
|
+
React.useEffect(() => {
|
134
|
+
return () => {
|
135
|
+
if (didDisposeInMemo.current) {
|
136
|
+
// console.debug('unmount', keyRef.current, 'skip')
|
137
|
+
didDisposeInMemo.current = false
|
138
|
+
return
|
139
|
+
}
|
140
|
+
|
141
|
+
// console.debug('unmount', keyRef.current)
|
142
|
+
const cachedItem = cache.get(key)
|
143
|
+
// If the stateful resource is already cleaned up, do nothing.
|
144
|
+
if (cachedItem === undefined || cachedItem._tag === 'destroyed') return
|
145
|
+
|
146
|
+
cachedItem.rc--
|
147
|
+
|
148
|
+
// console.debug('rc--', cachedItem.rc, ...(_options?.debugPrint?.(cachedItem.resource) ?? []))
|
149
|
+
|
150
|
+
if (cachedItem.rc === 0) {
|
151
|
+
dispose(cachedItem.resource)
|
152
|
+
cache.delete(key)
|
153
|
+
}
|
154
|
+
}
|
155
|
+
// We assume the `dispose` function is stable and won't change across renders
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
157
|
+
}, [key])
|
158
|
+
|
159
|
+
keyRef.current = key
|
160
|
+
|
161
|
+
return resource
|
162
|
+
}
|
163
|
+
|
164
|
+
// NOTE Given `useMemo` will be called multiple times (e.g. when using React Strict mode or Fast Refresh),
|
165
|
+
// we are using this cache to avoid starting multiple queries/spans for the same component.
|
166
|
+
// This is somewhat against some recommended React best practices, but it should be fine in our case below.
|
167
|
+
// Please definitely open an issue if you see or run into any problems with this approach!
|
168
|
+
const cache = new Map<
|
169
|
+
string,
|
170
|
+
| {
|
171
|
+
_tag: 'active'
|
172
|
+
rc: number
|
173
|
+
resource: any
|
174
|
+
}
|
175
|
+
| {
|
176
|
+
_tag: 'destroyed'
|
177
|
+
}
|
178
|
+
>()
|
179
|
+
|
180
|
+
export const __resetUseRcResourceCache = () => {
|
181
|
+
cache.clear()
|
182
|
+
}
|
package/src/useStore.ts
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import type { Store } from '@livestore/livestore'
|
2
|
+
import React from 'react'
|
3
|
+
|
4
|
+
import type { ReactApi } from './LiveStoreContext.js'
|
5
|
+
import { LiveStoreContext } from './LiveStoreContext.js'
|
6
|
+
import { useClientDocument } from './useClientDocument.js'
|
7
|
+
import { useQuery } from './useQuery.js'
|
8
|
+
|
9
|
+
export const withReactApi = (store: Store): Store & ReactApi => {
|
10
|
+
// @ts-expect-error TODO properly implement this
|
11
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
12
|
+
store.useQuery = (queryDef) => useQuery(queryDef, { store })
|
13
|
+
// @ts-expect-error TODO properly implement this
|
14
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
15
|
+
store.useClientDocument = (table, idOrOptions, options) => useClientDocument(table, idOrOptions, options, { store })
|
16
|
+
return store as Store & ReactApi
|
17
|
+
}
|
18
|
+
|
19
|
+
export const useStore = (options?: { store?: Store }): { store: Store & ReactApi } => {
|
20
|
+
if (options?.store !== undefined) {
|
21
|
+
return { store: withReactApi(options.store) }
|
22
|
+
}
|
23
|
+
|
24
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
25
|
+
const storeContext = React.useContext(LiveStoreContext)
|
26
|
+
|
27
|
+
if (storeContext === undefined) {
|
28
|
+
throw new Error(`useStore can only be used inside StoreContext.Provider`)
|
29
|
+
}
|
30
|
+
|
31
|
+
if (storeContext.stage !== 'running') {
|
32
|
+
throw new Error(`useStore can only be used after the store is running`)
|
33
|
+
}
|
34
|
+
|
35
|
+
return { store: withReactApi(storeContext.store) }
|
36
|
+
}
|
package/dist/useAtom.d.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
import type { QueryInfo } from '@livestore/common';
|
2
|
-
import type { LiveQuery } from '@livestore/livestore';
|
3
|
-
import type { Dispatch, SetStateAction } from './useRow.js';
|
4
|
-
export declare const useAtom: <TQuery extends LiveQuery<any, QueryInfo.Row | QueryInfo.Col>>(query$: TQuery) => [value: TQuery["__result!"], setValue: Dispatch<SetStateAction<Partial<TQuery["__result!"]>>>];
|
5
|
-
//# sourceMappingURL=useAtom.d.ts.map
|
package/dist/useAtom.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useAtom.d.ts","sourceRoot":"","sources":["../src/useAtom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAKrD,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3D,eAAO,MAAM,OAAO,GAElB,MAAM,SAAS,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,UAEpD,MAAM,KACb,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAoC/F,CAAA"}
|
package/dist/useAtom.js
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { useStore } from './LiveStoreContext.js';
|
3
|
-
import { useQueryRef } from './useQuery.js';
|
4
|
-
export const useAtom = (query$) => {
|
5
|
-
const query$Ref = useQueryRef(query$);
|
6
|
-
const { store } = useStore();
|
7
|
-
// TODO make API equivalent to useRow
|
8
|
-
const setValue = React.useMemo(() => {
|
9
|
-
return (newValueOrFn) => {
|
10
|
-
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn;
|
11
|
-
const table = query$.queryInfo.table;
|
12
|
-
if (query$.queryInfo._tag === 'Row') {
|
13
|
-
if (table.options.isSingleton && table.options.isSingleColumn) {
|
14
|
-
store.mutate(table.update(newValue));
|
15
|
-
}
|
16
|
-
else if (table.options.isSingleColumn) {
|
17
|
-
store.mutate(table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }));
|
18
|
-
}
|
19
|
-
else {
|
20
|
-
store.mutate(table.update({ where: { id: query$.queryInfo.id }, values: newValue }));
|
21
|
-
}
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
if (table.options.isSingleton && table.options.isSingleColumn) {
|
25
|
-
store.mutate(table.update({ [query$.queryInfo.column]: newValue }));
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
store.mutate(table.update({
|
29
|
-
where: { id: query$.queryInfo.id },
|
30
|
-
values: { [query$.queryInfo.column]: newValue },
|
31
|
-
}));
|
32
|
-
}
|
33
|
-
}
|
34
|
-
};
|
35
|
-
}, [query$.queryInfo, query$Ref, store]);
|
36
|
-
return [query$Ref.current, setValue];
|
37
|
-
};
|
38
|
-
//# sourceMappingURL=useAtom.js.map
|
package/dist/useAtom.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useAtom.js","sourceRoot":"","sources":["../src/useAtom.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,OAAO,GAAG,CAIrB,MAAc,EACkF,EAAE;IAClG,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAErC,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE5B,qCAAqC;IACrC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAgD,GAAG,EAAE;QACjF,OAAO,CAAC,YAAiB,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAA;YACpG,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,KACqC,CAAA;YAEpE,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACpC,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;oBAC9D,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;gBACtC,CAAC;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;oBACxC,KAAK,CAAC,MAAM,CAAC,KAAK,CA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
import { DbSchema } from '@livestore/common/schema';
|
4
|
-
import type { LiveQuery, ReactivityGraph } from '@livestore/livestore';
|
5
|
-
export type UseRowResult<TTableDef extends DbSchema.TableDefBase> = [
|
6
|
-
row: RowQuery.Result<TTableDef>,
|
7
|
-
setRow: StateSetters<TTableDef>,
|
8
|
-
query$: LiveQuery<RowQuery.Result<TTableDef>, QueryInfo>
|
9
|
-
];
|
10
|
-
export type UseRowOptionsBase = {
|
11
|
-
reactivityGraph?: ReactivityGraph;
|
12
|
-
};
|
13
|
-
/**
|
14
|
-
* Similar to `React.useState` but returns a tuple of `[row, setRow, query$]` for a given table where ...
|
15
|
-
*
|
16
|
-
* - `row` is the current value of the row (fully decoded according to the table schema)
|
17
|
-
* - `setRow` is a function that can be used to update the row (values will be encoded according to the table schema)
|
18
|
-
* - `query$` is a `LiveQuery` that e.g. can be used to subscribe to changes to the row
|
19
|
-
*
|
20
|
-
* If the table is a singleton table, `useRow` can be called without an `id` argument. Otherwise, the `id` argument is required.
|
21
|
-
*/
|
22
|
-
export declare const useRow: {
|
23
|
-
<TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDef, DbSchema.TableOptions & {
|
24
|
-
isSingleton: true;
|
25
|
-
deriveMutations: {
|
26
|
-
enabled: true;
|
27
|
-
};
|
28
|
-
}>>(table: TTableDef, options?: UseRowOptionsBase): UseRowResult<TTableDef>;
|
29
|
-
<TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDef, DbSchema.TableOptions & {
|
30
|
-
isSingleton: false;
|
31
|
-
requiredInsertColumnNames: 'id';
|
32
|
-
deriveMutations: {
|
33
|
-
enabled: true;
|
34
|
-
};
|
35
|
-
}>>(table: TTableDef, id: string | SessionIdSymbol, options?: UseRowOptionsBase & Partial<RowQuery.RequiredColumnsOptions<TTableDef>>): UseRowResult<TTableDef>;
|
36
|
-
<TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDef, DbSchema.TableOptions & {
|
37
|
-
isSingleton: false;
|
38
|
-
deriveMutations: {
|
39
|
-
enabled: true;
|
40
|
-
};
|
41
|
-
}>>(table: TTableDef, id: string | SessionIdSymbol, options: UseRowOptionsBase & RowQuery.RequiredColumnsOptions<TTableDef>): UseRowResult<TTableDef>;
|
42
|
-
};
|
43
|
-
export type Dispatch<A> = (action: A) => void;
|
44
|
-
export type SetStateAction<S> = S | ((previousValue: S) => S);
|
45
|
-
export type StateSetters<TTableDef extends DbSchema.TableDefBase> = TTableDef['options']['isSingleColumn'] extends true ? Dispatch<SetStateAction<RowQuery.Result<TTableDef>>> : {
|
46
|
-
[K in keyof RowQuery.Result<TTableDef>]: Dispatch<SetStateAction<RowQuery.Result<TTableDef>[K]>>;
|
47
|
-
} & {
|
48
|
-
setMany: Dispatch<SetStateAction<Partial<RowQuery.Result<TTableDef>>>>;
|
49
|
-
};
|
50
|
-
//# sourceMappingURL=useRow.d.ts.map
|
package/dist/useRow.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useRow.d.ts","sourceRoot":"","sources":["../src/useRow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAUtE,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,QAAQ,CAAC,YAAY,IAAI;IAClE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC;IAC/B,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CACzD,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,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AAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAA;AAC7C,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;AAE7D,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,QAAQ,CAAC,YAAY,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,SAAS,IAAI,GACnH,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GACpD;KACG,CAAC,IAAI,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjG,GAAG;IACF,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;CACvE,CAAA"}
|
package/dist/useRow.js
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
import { SessionIdSymbol } from '@livestore/common';
|
2
|
-
import { DbSchema } from '@livestore/common/schema';
|
3
|
-
import { queryDb } from '@livestore/livestore';
|
4
|
-
import { shouldNeverHappen } from '@livestore/utils';
|
5
|
-
import { ReadonlyRecord } from '@livestore/utils/effect';
|
6
|
-
import React from 'react';
|
7
|
-
import { useStore } from './LiveStoreContext.js';
|
8
|
-
import { useQueryRef } from './useQuery.js';
|
9
|
-
import { useMakeScopedQuery } from './useScopedQuery.js';
|
10
|
-
/**
|
11
|
-
* Similar to `React.useState` but returns a tuple of `[row, setRow, query$]` for a given table where ...
|
12
|
-
*
|
13
|
-
* - `row` is the current value of the row (fully decoded according to the table schema)
|
14
|
-
* - `setRow` is a function that can be used to update the row (values will be encoded according to the table schema)
|
15
|
-
* - `query$` is a `LiveQuery` that e.g. can be used to subscribe to changes to the row
|
16
|
-
*
|
17
|
-
* If the table is a singleton table, `useRow` can be called without an `id` argument. Otherwise, the `id` argument is required.
|
18
|
-
*/
|
19
|
-
export const useRow = (table, idOrOptions, options_) => {
|
20
|
-
const sqliteTableDef = table.sqliteDef;
|
21
|
-
const id = typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol ? idOrOptions : undefined;
|
22
|
-
const options = typeof idOrOptions === 'string' || idOrOptions === SessionIdSymbol ? options_ : idOrOptions;
|
23
|
-
const { insertValues, reactivityGraph } = options ?? {};
|
24
|
-
const tableName = table.sqliteDef.name;
|
25
|
-
if (DbSchema.tableHasDerivedMutations(table) === false) {
|
26
|
-
shouldNeverHappen(`useRow called on table "${tableName}" which does not have 'deriveMutations: true' set`);
|
27
|
-
}
|
28
|
-
const { store } = useStore();
|
29
|
-
if (store.schema.tables.has(table.sqliteDef.name) === false &&
|
30
|
-
table.sqliteDef.name.startsWith('__livestore') === false) {
|
31
|
-
shouldNeverHappen(`Table "${table.sqliteDef.name}" not found in schema`);
|
32
|
-
}
|
33
|
-
// console.debug('useRow', tableName, id)
|
34
|
-
const idStr = id === SessionIdSymbol ? 'session' : id;
|
35
|
-
const rowQuery = table.query.row;
|
36
|
-
const { query$, otelContext } = useMakeScopedQuery((otelContext) => DbSchema.tableIsSingleton(table)
|
37
|
-
? queryDb(rowQuery(), { reactivityGraph, otelContext })
|
38
|
-
: queryDb(rowQuery(id, { insertValues: insertValues }), { reactivityGraph, otelContext }), [idStr, tableName], {
|
39
|
-
otel: {
|
40
|
-
spanName: `LiveStore:useRow:${tableName}${idStr === undefined ? '' : `:${idStr}`}`,
|
41
|
-
attributes: { id: idStr },
|
42
|
-
},
|
43
|
-
});
|
44
|
-
const query$Ref = useQueryRef(query$, otelContext);
|
45
|
-
const setState = React.useMemo(() => {
|
46
|
-
if (table.options.isSingleColumn) {
|
47
|
-
return (newValueOrFn) => {
|
48
|
-
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn;
|
49
|
-
if (query$Ref.current === newValue)
|
50
|
-
return;
|
51
|
-
// NOTE we need to account for the short-hand syntax for single-column+singleton tables
|
52
|
-
if (table.options.isSingleton) {
|
53
|
-
store.mutate(table.update(newValue));
|
54
|
-
}
|
55
|
-
else {
|
56
|
-
store.mutate(table.update({ where: { id }, values: { value: newValue } }));
|
57
|
-
}
|
58
|
-
// store.mutate(updateMutationForQueryInfo(query$.queryInfo!, { value: newValue }))
|
59
|
-
};
|
60
|
-
}
|
61
|
-
else {
|
62
|
-
const setState = // TODO: do we have a better type for the values that can go in SQLite?
|
63
|
-
ReadonlyRecord.map(sqliteTableDef.columns, (column, columnName) => (newValueOrFn) => {
|
64
|
-
const newValue =
|
65
|
-
// @ts-expect-error TODO fix typing
|
66
|
-
typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current[columnName]) : newValueOrFn;
|
67
|
-
// Don't update the state if it's the same as the value already seen in the component
|
68
|
-
// @ts-expect-error TODO fix typing
|
69
|
-
if (query$Ref.current[columnName] === newValue)
|
70
|
-
return;
|
71
|
-
store.mutate(table.update({ where: { id: id ?? 'singleton' }, values: { [columnName]: newValue } }));
|
72
|
-
// store.mutate(updateMutationForQueryInfo(query$.queryInfo!, { [columnName]: newValue }))
|
73
|
-
});
|
74
|
-
setState.setMany = (columnValuesOrFn) => {
|
75
|
-
const columnValues =
|
76
|
-
// @ts-expect-error TODO fix typing
|
77
|
-
typeof columnValuesOrFn === 'function' ? columnValuesOrFn(query$Ref.current) : columnValuesOrFn;
|
78
|
-
// TODO use hashing instead
|
79
|
-
// Don't update the state if it's the same as the value already seen in the component
|
80
|
-
if (
|
81
|
-
// @ts-expect-error TODO fix typing
|
82
|
-
Object.entries(columnValues).every(([columnName, value]) => query$Ref.current[columnName] === value)) {
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
store.mutate(table.update({ where: { id: id ?? 'singleton' }, values: columnValues }));
|
86
|
-
// store.mutate(updateMutationForQueryInfo(query$.queryInfo!, columnValues))
|
87
|
-
};
|
88
|
-
return setState;
|
89
|
-
}
|
90
|
-
}, [id, query$Ref, sqliteTableDef.columns, store, table]);
|
91
|
-
return [query$Ref.current, setState, query$];
|
92
|
-
};
|
93
|
-
//# sourceMappingURL=useRow.js.map
|
package/dist/useRow.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useRow.js","sourceRoot":"","sources":["../src/useRow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAYxD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,MAAM,GAoCf,CAMF,KAAgB,EAChB,WAA0D,EAC1D,QAAkF,EACzD,EAAE;IAC3B,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,CAAA;IACtC,MAAM,EAAE,GAAG,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,eAAe,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAA;IACvG,MAAM,OAAO,GACX,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAA;IAC7F,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,OAAO,IAAI,EAAE,CA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