@livestore/react 0.3.0-dev.27 → 0.3.0-dev.29
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/LiveStoreContext.d.ts +10 -6
- package/dist/LiveStoreContext.d.ts.map +1 -1
- package/dist/LiveStoreContext.js +0 -14
- package/dist/LiveStoreContext.js.map +1 -1
- package/dist/LiveStoreProvider.d.ts +2 -2
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +5 -1
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +6 -5
- package/dist/LiveStoreProvider.test.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +115 -546
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +64 -22
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/mod.d.ts +4 -4
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -4
- 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/{useRow.test.js → useClientDocument.test.js} +44 -48
- package/dist/useClientDocument.test.js.map +1 -0
- package/dist/useQuery.d.ts +1 -3
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +6 -3
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +16 -17
- package/dist/useQuery.test.js.map +1 -1
- 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/package.json +11 -11
- package/src/LiveStoreContext.ts +10 -19
- package/src/LiveStoreProvider.test.tsx +6 -5
- package/src/LiveStoreProvider.tsx +7 -4
- package/src/__snapshots__/{useRow.test.tsx.snap → useClientDocument.test.tsx.snap} +62 -46
- package/src/__snapshots__/useQuery.test.tsx.snap +8 -8
- package/src/__tests__/fixture.tsx +69 -39
- package/src/mod.ts +5 -5
- package/src/{useRow.test.tsx → useClientDocument.test.tsx} +51 -55
- package/src/useClientDocument.ts +157 -0
- package/src/useQuery.test.tsx +18 -19
- package/src/useQuery.ts +9 -8
- package/src/useStore.ts +36 -0
- package/tmp/pack.tgz +0 -0
- package/dist/useAtom.d.ts +0 -8
- package/dist/useAtom.d.ts.map +0 -1
- package/dist/useAtom.js +0 -42
- package/dist/useAtom.js.map +0 -1
- package/dist/useRow.d.ts +0 -64
- package/dist/useRow.d.ts.map +0 -1
- package/dist/useRow.js +0 -108
- 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.map +0 -1
- package/src/useAtom.ts +0 -66
- package/src/useRow.ts +0 -210
package/dist/useQuery.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { extractStackInfoFromStackTrace, stackInfoToString } from '@livestore/livestore';
|
|
2
|
-
import { deepEqual, indent } from '@livestore/utils';
|
|
2
|
+
import { deepEqual, indent, shouldNeverHappen } from '@livestore/utils';
|
|
3
3
|
import * as otel from '@opentelemetry/api';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { LiveStoreContext } from './LiveStoreContext.js';
|
|
6
6
|
import { useRcResource } from './useRcResource.js';
|
|
7
7
|
import { originalStackLimit } from './utils/stack-info.js';
|
|
8
8
|
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
|
|
@@ -21,7 +21,10 @@ export const useQuery = (queryDef, options) => useQueryRef(queryDef, options).va
|
|
|
21
21
|
/**
|
|
22
22
|
*/
|
|
23
23
|
export const useQueryRef = (queryDef, options) => {
|
|
24
|
-
const
|
|
24
|
+
const store = options?.store ??
|
|
25
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
26
|
+
React.useContext(LiveStoreContext)?.store ??
|
|
27
|
+
shouldNeverHappen(`No store provided to useQuery`);
|
|
25
28
|
const rcRefKey = `${store.storeId}_${queryDef.hash}`;
|
|
26
29
|
const stackInfo = React.useMemo(() => {
|
|
27
30
|
Error.stackTraceLimit = 10;
|
package/dist/useQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAA;AAEtF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,OAA2B,EACI,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAA;AAEnF;GACG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,QAAgB,EAChB,OA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U,CAAC,OAAO,EAAE,YAAY,IAAI,sBAAsB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QAE9E,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE;YAC7B,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACrB,qEAAqE;gBACrE,kEAAkE;gBAClE,sCAAsC;gBACtC,IAAI,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,KAAK,EAAE,CAAC;oBACpD,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBACpB,CAAC;YACH,CAAC;YACD,gBAAgB,EAAE,GAAG,EAAE;gBACrB,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAC9C,CAAC;YACD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW;SACZ,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;IAE5F,aAAa,CACX,QAAQ,EACR,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAC5B,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE;QACvB,sEAAsE;QACtE,UAAU,CAAC,KAAK,EAAE,CAAA;QAClB,IAAI,CAAC,GAAG,EAAE,CAAA;IACZ,CAAC,CACF,CAAA;IAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAA;AACjC,CAAC,CAAA"}
|
package/dist/useQuery.test.js
CHANGED
|
@@ -9,8 +9,7 @@ import React from 'react';
|
|
|
9
9
|
// @ts-expect-error no types
|
|
10
10
|
import * as ReactWindow from 'react-window';
|
|
11
11
|
import { expect } from 'vitest';
|
|
12
|
-
import { makeTodoMvcReact, tables
|
|
13
|
-
import * as LiveStoreReact from './mod.js';
|
|
12
|
+
import { events, makeTodoMvcReact, tables } from './__tests__/fixture.js';
|
|
14
13
|
import { __resetUseRcResourceCache } from './useRcResource.js';
|
|
15
14
|
Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (strictMode=%s)', ({ strictMode }) => {
|
|
16
15
|
Vitest.afterEach(() => {
|
|
@@ -19,15 +18,15 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
19
18
|
});
|
|
20
19
|
Vitest.scopedLive('simple', () => Effect.gen(function* () {
|
|
21
20
|
const { wrapper, store, renderCount } = yield* makeTodoMvcReact({ strictMode });
|
|
22
|
-
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.
|
|
21
|
+
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) });
|
|
23
22
|
const { result } = ReactTesting.renderHook(() => {
|
|
24
23
|
renderCount.inc();
|
|
25
|
-
return
|
|
24
|
+
return store.useQuery(allTodos$);
|
|
26
25
|
}, { wrapper });
|
|
27
26
|
expect(result.current.length).toBe(0);
|
|
28
27
|
expect(renderCount.val).toBe(1);
|
|
29
28
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
30
|
-
ReactTesting.act(() => store.commit(
|
|
29
|
+
ReactTesting.act(() => store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false })));
|
|
31
30
|
expect(result.current.length).toBe(1);
|
|
32
31
|
expect(result.current[0].text).toBe('buy milk');
|
|
33
32
|
expect(renderCount.val).toBe(2);
|
|
@@ -35,21 +34,21 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
35
34
|
}));
|
|
36
35
|
Vitest.scopedLive('same `useQuery` hook invoked with different queries', () => Effect.gen(function* () {
|
|
37
36
|
const { wrapper, store, renderCount } = yield* makeTodoMvcReact({ strictMode });
|
|
38
|
-
const todo1$ = queryDb({ query: `select * from todos where id = 't1'`, schema: Schema.Array(tables.todos.
|
|
39
|
-
const todo2$ = queryDb({ query: `select * from todos where id = 't2'`, schema: Schema.Array(tables.todos.
|
|
40
|
-
store.commit(
|
|
37
|
+
const todo1$ = queryDb({ query: `select * from todos where id = 't1'`, schema: Schema.Array(tables.todos.rowSchema) }, { label: 'libraryTracksView1' });
|
|
38
|
+
const todo2$ = queryDb({ query: `select * from todos where id = 't2'`, schema: Schema.Array(tables.todos.rowSchema) }, { label: 'libraryTracksView2' });
|
|
39
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }), events.todoCreated({ id: 't2', text: 'buy eggs', completed: false }));
|
|
41
40
|
const { result, rerender } = ReactTesting.renderHook((todoId) => {
|
|
42
41
|
renderCount.inc();
|
|
43
42
|
const query$ = React.useMemo(() => (todoId === 't1' ? todo1$ : todo2$), [todoId]);
|
|
44
|
-
return
|
|
43
|
+
return store.useQuery(query$)[0].text;
|
|
45
44
|
}, { wrapper, initialProps: 't1' });
|
|
46
45
|
expect(result.current).toBe('buy milk');
|
|
47
46
|
expect(renderCount.val).toBe(1);
|
|
48
47
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('1: after first render');
|
|
49
|
-
ReactTesting.act(() => store.commit(
|
|
48
|
+
ReactTesting.act(() => store.commit(events.todoUpdated({ id: 't1', text: 'buy soy milk' })));
|
|
50
49
|
expect(result.current).toBe('buy soy milk');
|
|
51
50
|
expect(renderCount.val).toBe(2);
|
|
52
|
-
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('2: after first
|
|
51
|
+
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('2: after first commit');
|
|
53
52
|
rerender('t2');
|
|
54
53
|
expect(result.current).toBe('buy eggs');
|
|
55
54
|
expect(renderCount.val).toBe(3);
|
|
@@ -58,16 +57,16 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
58
57
|
Vitest.scopedLive('filtered dependency query', () => Effect.gen(function* () {
|
|
59
58
|
const { wrapper, store, renderCount } = yield* makeTodoMvcReact({ strictMode });
|
|
60
59
|
const filter$ = makeRef('t1', { label: 'id-filter' });
|
|
61
|
-
const todo$ = queryDb((get) => tables.todos.
|
|
62
|
-
store.commit(
|
|
60
|
+
const todo$ = queryDb((get) => tables.todos.where('id', get(filter$)), { label: 'todo' });
|
|
61
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }), events.todoCreated({ id: 't2', text: 'buy eggs', completed: false }));
|
|
63
62
|
const { result } = ReactTesting.renderHook(() => {
|
|
64
63
|
renderCount.inc();
|
|
65
|
-
return
|
|
64
|
+
return store.useQuery(todo$)[0].text;
|
|
66
65
|
}, { wrapper });
|
|
67
66
|
expect(result.current).toBe('buy milk');
|
|
68
67
|
expect(renderCount.val).toBe(1);
|
|
69
68
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
70
|
-
ReactTesting.act(() => store.commit(
|
|
69
|
+
ReactTesting.act(() => store.commit(events.todoUpdated({ id: 't1', text: 'buy soy milk' })));
|
|
71
70
|
expect(result.current).toBe('buy soy milk');
|
|
72
71
|
expect(renderCount.val).toBe(2);
|
|
73
72
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
@@ -80,13 +79,13 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
80
79
|
// it basically causes a "query swap" in the `useMemo` and both a `useEffect` cleanup call.
|
|
81
80
|
// To handle this properly we introduced the `_tag: 'destroyed'` state in the `spanAlreadyStartedCache`.
|
|
82
81
|
Vitest.scopedLive('should work for a list with react-window', () => Effect.gen(function* () {
|
|
83
|
-
const { wrapper } = yield* makeTodoMvcReact({ strictMode });
|
|
82
|
+
const { wrapper, store } = yield* makeTodoMvcReact({ strictMode });
|
|
84
83
|
const ListWrapper = ({ numItems }) => {
|
|
85
84
|
return (React.createElement(ReactWindow.FixedSizeList, { height: 100, width: 100, itemSize: 10, itemCount: numItems, itemData: Array.from({ length: numItems }, (_, i) => i).reverse() }, ListItem));
|
|
86
85
|
};
|
|
87
86
|
const ListItem = ({ data: ids, index }) => {
|
|
88
87
|
const id = ids[index];
|
|
89
|
-
const res =
|
|
88
|
+
const res = store.useQuery(LiveStore.computed(() => id, { label: `ListItem.${id}`, deps: id }));
|
|
90
89
|
return React.createElement("div", { role: "listitem" }, res);
|
|
91
90
|
};
|
|
92
91
|
const renderResult = ReactTesting.render(React.createElement(ListWrapper, { numItems: 1 }), { wrapper });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.test.js","sourceRoot":"","sources":["../src/useQuery.test.tsx"],"names":[],"mappings":"AAAA,OAAO,uCAAuC,CAAA;AAE9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,EAAE,EAAE,MAAM,6CAA6C,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,4BAA4B;AAC5B,OAAO,KAAK,WAAW,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useQuery.test.js","sourceRoot":"","sources":["../src/useQuery.test.tsx"],"names":[],"mappings":"AAAA,OAAO,uCAAuC,CAAA;AAE9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,EAAE,EAAE,MAAM,6CAA6C,CAAA;AAChE,OAAO,EAA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QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,IAEhE,QAAQ,CACiB,CAC7B,CAAA;QACH,CAAC,CAAA;QAED,MAAM,QAAQ,GAA6D,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;YAClG,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAE,CAAA;YACtB,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;YAC/F,OAAO,6BAAK,IAAI,EAAC,UAAU,IAAE,GAAG,CAAO,CAAA;QACzC,CAAC,CAAA;QAED,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,oBAAC,WAAW,IAAC,QAAQ,EAAE,CAAC,GAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAEnF,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEpD,YAAY,CAAC,QAAQ,CAAC,oBAAC,WAAW,IAAC,QAAQ,EAAE,CAAC,GAAI,CAAC,CAAA;QAEnD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvD,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CACF,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Store } from '@livestore/livestore';
|
|
2
|
+
import type { ReactApi } from './LiveStoreContext.js';
|
|
3
|
+
export declare const withReactApi: (store: Store) => Store & ReactApi;
|
|
4
|
+
export declare const useStore: (options?: {
|
|
5
|
+
store?: Store;
|
|
6
|
+
}) => {
|
|
7
|
+
store: Store & ReactApi;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=useStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAGjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAKrD,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,KAAG,KAAK,GAAG,QAQnD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,UAAU;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,KAAG;IAAE,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAA;CAiB/E,CAAA"}
|
package/dist/useStore.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LiveStoreContext } from './LiveStoreContext.js';
|
|
3
|
+
import { useClientDocument } from './useClientDocument.js';
|
|
4
|
+
import { useQuery } from './useQuery.js';
|
|
5
|
+
export const withReactApi = (store) => {
|
|
6
|
+
// @ts-expect-error TODO properly implement this
|
|
7
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
8
|
+
store.useQuery = (queryDef) => useQuery(queryDef, { store });
|
|
9
|
+
// @ts-expect-error TODO properly implement this
|
|
10
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
|
+
store.useClientDocument = (table, idOrOptions, options) => useClientDocument(table, idOrOptions, options, { store });
|
|
12
|
+
return store;
|
|
13
|
+
};
|
|
14
|
+
export const useStore = (options) => {
|
|
15
|
+
if (options?.store !== undefined) {
|
|
16
|
+
return { store: withReactApi(options.store) };
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
19
|
+
const storeContext = React.useContext(LiveStoreContext);
|
|
20
|
+
if (storeContext === undefined) {
|
|
21
|
+
throw new Error(`useStore can only be used inside StoreContext.Provider`);
|
|
22
|
+
}
|
|
23
|
+
if (storeContext.stage !== 'running') {
|
|
24
|
+
throw new Error(`useStore can only be used after the store is running`);
|
|
25
|
+
}
|
|
26
|
+
return { store: withReactApi(storeContext.store) };
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.js","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAY,EAAoB,EAAE;IAC7D,gDAAgD;IAChD,sDAAsD;IACtD,KAAK,CAAC,QAAQ,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC5D,gDAAgD;IAChD,sDAAsD;IACtD,KAAK,CAAC,iBAAiB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACpH,OAAO,KAAyB,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAA2B,EAA+B,EAAE;IACnF,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAA;IAC/C,CAAC;IAED,sDAAsD;IACtD,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAEvD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;IAC3E,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAA;AACpD,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/react",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -23,27 +23,27 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@opentelemetry/api": "1.9.0",
|
|
26
|
-
"@livestore/
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/common": "0.3.0-dev.
|
|
26
|
+
"@livestore/utils": "0.3.0-dev.29",
|
|
27
|
+
"@livestore/livestore": "0.3.0-dev.29",
|
|
28
|
+
"@livestore/common": "0.3.0-dev.29"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@opentelemetry/sdk-trace-base": "^
|
|
31
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
32
32
|
"@testing-library/dom": "^10.4.0",
|
|
33
33
|
"@testing-library/react": "^16.2.0",
|
|
34
34
|
"@types/react": "^19.0.10",
|
|
35
35
|
"@types/react-dom": "^19.0.4",
|
|
36
36
|
"jsdom": "^26.0.0",
|
|
37
|
-
"react": "^19.
|
|
38
|
-
"react-dom": "^19.
|
|
37
|
+
"react": "^19.1.0",
|
|
38
|
+
"react-dom": "^19.1.0",
|
|
39
39
|
"react-window": "^1.8.11",
|
|
40
|
-
"typescript": "^5.8.
|
|
40
|
+
"typescript": "^5.8.3",
|
|
41
41
|
"vite": "^6.2.1",
|
|
42
|
-
"vitest": "^3.
|
|
43
|
-
"@livestore/adapter-web": "0.3.0-dev.
|
|
42
|
+
"vitest": "^3.1.1",
|
|
43
|
+
"@livestore/adapter-web": "0.3.0-dev.29"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"react": "~19.
|
|
46
|
+
"react": "~19.1.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
package/src/LiveStoreContext.ts
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import type { LiveStoreContextRunning
|
|
1
|
+
import type { LiveStoreContextRunning } from '@livestore/livestore'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import type { useClientDocument } from './useClientDocument.js'
|
|
5
|
+
import type { useQuery } from './useQuery.js'
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
12
|
-
const storeContext = React.useContext(LiveStoreContext)
|
|
13
|
-
|
|
14
|
-
if (storeContext === undefined) {
|
|
15
|
-
throw new Error(`useStore can only be used inside StoreContext.Provider`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (storeContext.stage !== 'running') {
|
|
19
|
-
throw new Error(`useStore can only be used after the store is running`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return storeContext
|
|
7
|
+
export type ReactApi = {
|
|
8
|
+
useQuery: typeof useQuery
|
|
9
|
+
useClientDocument: typeof useClientDocument
|
|
23
10
|
}
|
|
11
|
+
|
|
12
|
+
export const LiveStoreContext = React.createContext<
|
|
13
|
+
{ stage: 'running'; store: LiveStoreContextRunning['store'] & ReactApi } | undefined
|
|
14
|
+
>(undefined)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
2
2
|
import { sql } from '@livestore/common'
|
|
3
|
-
import {
|
|
3
|
+
import { rawSqlEvent } from '@livestore/common/schema'
|
|
4
4
|
import { queryDb, type Store } from '@livestore/livestore'
|
|
5
5
|
import { Schema } from '@livestore/utils/effect'
|
|
6
6
|
import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react'
|
|
@@ -16,12 +16,13 @@ describe('LiveStoreProvider', () => {
|
|
|
16
16
|
it('simple', async () => {
|
|
17
17
|
let appRenderCount = 0
|
|
18
18
|
|
|
19
|
-
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.
|
|
19
|
+
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) })
|
|
20
20
|
|
|
21
21
|
const App = () => {
|
|
22
22
|
appRenderCount++
|
|
23
|
+
const { store } = LiveStoreReact.useStore()
|
|
23
24
|
|
|
24
|
-
const todos =
|
|
25
|
+
const todos = store.useQuery(allTodos$)
|
|
25
26
|
|
|
26
27
|
return <div>{JSON.stringify(todos)}</div>
|
|
27
28
|
}
|
|
@@ -32,7 +33,7 @@ describe('LiveStoreProvider', () => {
|
|
|
32
33
|
const bootCb = React.useCallback(
|
|
33
34
|
(store: Store) =>
|
|
34
35
|
store.commit(
|
|
35
|
-
|
|
36
|
+
rawSqlEvent({
|
|
36
37
|
sql: sql`INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
37
38
|
}),
|
|
38
39
|
),
|
|
@@ -89,7 +90,7 @@ describe('LiveStoreProvider', () => {
|
|
|
89
90
|
const bootCb = React.useCallback(
|
|
90
91
|
(store: Store) =>
|
|
91
92
|
store.commit(
|
|
92
|
-
|
|
93
|
+
rawSqlEvent({
|
|
93
94
|
sql: sql`INSERT OR IGNORE INTO todos_missing_table (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
94
95
|
}),
|
|
95
96
|
),
|
|
@@ -47,12 +47,12 @@ export interface LiveStoreProviderProps {
|
|
|
47
47
|
ctx: { migrationsReport: MigrationsReport; parentSpan: otel.Span },
|
|
48
48
|
) => void | Promise<void> | Effect.Effect<void, unknown, OtelTracer.OtelTracer>
|
|
49
49
|
otelOptions?: Partial<OtelOptions>
|
|
50
|
-
renderLoading
|
|
50
|
+
renderLoading?: (status: BootStatus) => ReactElement
|
|
51
51
|
renderError?: (error: UnexpectedError | unknown) => ReactElement
|
|
52
52
|
renderShutdown?: (cause: IntentionalShutdownCause | StoreInterrupted) => ReactElement
|
|
53
53
|
adapter: Adapter
|
|
54
54
|
/**
|
|
55
|
-
* In order for LiveStore to apply multiple
|
|
55
|
+
* In order for LiveStore to apply multiple events in a single render,
|
|
56
56
|
* you need to pass the `batchUpdates` function from either `react-dom` or `react-native`.
|
|
57
57
|
*
|
|
58
58
|
* ```ts
|
|
@@ -84,6 +84,7 @@ export interface LiveStoreProviderProps {
|
|
|
84
84
|
const defaultRenderError = (error: UnexpectedError | unknown) => (
|
|
85
85
|
<>{Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)}</>
|
|
86
86
|
)
|
|
87
|
+
|
|
87
88
|
const defaultRenderShutdown = (cause: IntentionalShutdownCause | StoreInterrupted) => {
|
|
88
89
|
const reason =
|
|
89
90
|
cause._tag === 'LiveStore.StoreInterrupted'
|
|
@@ -101,8 +102,10 @@ const defaultRenderShutdown = (cause: IntentionalShutdownCause | StoreInterrupte
|
|
|
101
102
|
return <>LiveStore Shutdown due to {reason}</>
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
const defaultRenderLoading = (status: BootStatus) => <>LiveStore is loading ({status.stage})...</>
|
|
106
|
+
|
|
104
107
|
export const LiveStoreProvider = ({
|
|
105
|
-
renderLoading,
|
|
108
|
+
renderLoading = defaultRenderLoading,
|
|
106
109
|
renderError = defaultRenderError,
|
|
107
110
|
renderShutdown = defaultRenderShutdown,
|
|
108
111
|
otelOptions,
|
|
@@ -148,7 +151,7 @@ export const LiveStoreProvider = ({
|
|
|
148
151
|
}
|
|
149
152
|
globalThis.__debugLiveStore[storeId] = storeCtx.store
|
|
150
153
|
|
|
151
|
-
return <LiveStoreContext.Provider value={storeCtx}>{children}</LiveStoreContext.Provider>
|
|
154
|
+
return <LiveStoreContext.Provider value={storeCtx as TODO}>{children}</LiveStoreContext.Provider>
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
type SchemaKey = string
|