@livestore/react 0.0.0-snapshot-2ef046b02334f52613d31dbe06af53487685edc0 → 0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46
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 +73 -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} +38 -43
- 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 +5 -5
- 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} +50 -30
- 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} +43 -49
- package/src/useClientDocument.ts +149 -0
- package/src/useQuery.test.tsx +18 -19
- package/src/useQuery.ts +9 -8
- package/src/useStore.ts +36 -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.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,E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AE,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,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,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.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@opentelemetry/api": "1.9.0",
|
|
26
|
-
"@livestore/common": "0.0.0-snapshot-
|
|
27
|
-
"@livestore/livestore": "0.0.0-snapshot-
|
|
28
|
-
"@livestore/utils": "0.0.0-snapshot-
|
|
26
|
+
"@livestore/common": "0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46",
|
|
27
|
+
"@livestore/livestore": "0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46",
|
|
28
|
+
"@livestore/utils": "0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typescript": "^5.8.2",
|
|
41
41
|
"vite": "^6.2.1",
|
|
42
42
|
"vitest": "^3.0.8",
|
|
43
|
-
"@livestore/adapter-web": "0.0.0-snapshot-
|
|
43
|
+
"@livestore/adapter-web": "0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "~19.0.0"
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
3
|
+
exports[`useClientDocument > otel > should update the data based on component key strictMode={ strictMode: false } 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"_name": "createStore",
|
|
6
6
|
"attributes": {
|
|
@@ -24,21 +24,26 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
24
24
|
"_name": "LiveStore:sync",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
"_name": "LiveStore:
|
|
27
|
+
"_name": "LiveStore:commits",
|
|
28
28
|
"children": [
|
|
29
29
|
{
|
|
30
30
|
"_name": "LiveStore:commit",
|
|
31
31
|
"attributes": {
|
|
32
|
-
"livestore.
|
|
33
|
-
"
|
|
32
|
+
"livestore.eventTags": [
|
|
33
|
+
"UserInfoSet",
|
|
34
34
|
],
|
|
35
|
-
"livestore.
|
|
35
|
+
"livestore.eventsCount": 1,
|
|
36
36
|
},
|
|
37
37
|
"children": [
|
|
38
38
|
{
|
|
39
39
|
"_name": "livestore.in-memory-db:execute",
|
|
40
40
|
"attributes": {
|
|
41
|
-
"sql.query": "
|
|
41
|
+
"sql.query": "
|
|
42
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
43
|
+
VALUES (?, ?)
|
|
44
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
45
|
+
value = json_set(value, ?, json(?))
|
|
46
|
+
",
|
|
42
47
|
},
|
|
43
48
|
},
|
|
44
49
|
],
|
|
@@ -49,9 +54,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
49
54
|
"_name": "LiveStore:queries",
|
|
50
55
|
"children": [
|
|
51
56
|
{
|
|
52
|
-
"_name": "LiveStore:
|
|
57
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u1",
|
|
53
58
|
"attributes": {
|
|
54
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
59
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
55
60
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
56
61
|
},
|
|
57
62
|
"children": [
|
|
@@ -67,16 +72,21 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
67
72
|
"_name": "LiveStore:commit",
|
|
68
73
|
"attributes": {
|
|
69
74
|
"livestore.commitLabel": "rowQuery:UserInfo:u1",
|
|
70
|
-
"livestore.
|
|
71
|
-
"
|
|
75
|
+
"livestore.eventTags": [
|
|
76
|
+
"UserInfoSet",
|
|
72
77
|
],
|
|
73
|
-
"livestore.
|
|
78
|
+
"livestore.eventsCount": 1,
|
|
74
79
|
},
|
|
75
80
|
"children": [
|
|
76
81
|
{
|
|
77
82
|
"_name": "livestore.in-memory-db:execute",
|
|
78
83
|
"attributes": {
|
|
79
|
-
"sql.query": "
|
|
84
|
+
"sql.query": "
|
|
85
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
86
|
+
VALUES (?, ?)
|
|
87
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
88
|
+
value = json_set(json_set(value, ?, json(?)), ?, json(?))
|
|
89
|
+
",
|
|
80
90
|
},
|
|
81
91
|
},
|
|
82
92
|
],
|
|
@@ -129,9 +139,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
129
139
|
],
|
|
130
140
|
},
|
|
131
141
|
{
|
|
132
|
-
"_name": "LiveStore:
|
|
142
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u2",
|
|
133
143
|
"attributes": {
|
|
134
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
144
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
135
145
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
136
146
|
},
|
|
137
147
|
"children": [
|
|
@@ -196,7 +206,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
196
206
|
}
|
|
197
207
|
`;
|
|
198
208
|
|
|
199
|
-
exports[`
|
|
209
|
+
exports[`useClientDocument > otel > should update the data based on component key strictMode={ strictMode: true } 1`] = `
|
|
200
210
|
{
|
|
201
211
|
"_name": "createStore",
|
|
202
212
|
"attributes": {
|
|
@@ -220,21 +230,26 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
220
230
|
"_name": "LiveStore:sync",
|
|
221
231
|
},
|
|
222
232
|
{
|
|
223
|
-
"_name": "LiveStore:
|
|
233
|
+
"_name": "LiveStore:commits",
|
|
224
234
|
"children": [
|
|
225
235
|
{
|
|
226
236
|
"_name": "LiveStore:commit",
|
|
227
237
|
"attributes": {
|
|
228
|
-
"livestore.
|
|
229
|
-
"
|
|
238
|
+
"livestore.eventTags": [
|
|
239
|
+
"UserInfoSet",
|
|
230
240
|
],
|
|
231
|
-
"livestore.
|
|
241
|
+
"livestore.eventsCount": 1,
|
|
232
242
|
},
|
|
233
243
|
"children": [
|
|
234
244
|
{
|
|
235
245
|
"_name": "livestore.in-memory-db:execute",
|
|
236
246
|
"attributes": {
|
|
237
|
-
"sql.query": "
|
|
247
|
+
"sql.query": "
|
|
248
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
249
|
+
VALUES (?, ?)
|
|
250
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
251
|
+
value = json_set(value, ?, json(?))
|
|
252
|
+
",
|
|
238
253
|
},
|
|
239
254
|
},
|
|
240
255
|
],
|
|
@@ -245,9 +260,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
245
260
|
"_name": "LiveStore:queries",
|
|
246
261
|
"children": [
|
|
247
262
|
{
|
|
248
|
-
"_name": "LiveStore:
|
|
263
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u1",
|
|
249
264
|
"attributes": {
|
|
250
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
265
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
251
266
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
252
267
|
},
|
|
253
268
|
"children": [
|
|
@@ -263,16 +278,21 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
263
278
|
"_name": "LiveStore:commit",
|
|
264
279
|
"attributes": {
|
|
265
280
|
"livestore.commitLabel": "rowQuery:UserInfo:u1",
|
|
266
|
-
"livestore.
|
|
267
|
-
"
|
|
281
|
+
"livestore.eventTags": [
|
|
282
|
+
"UserInfoSet",
|
|
268
283
|
],
|
|
269
|
-
"livestore.
|
|
284
|
+
"livestore.eventsCount": 1,
|
|
270
285
|
},
|
|
271
286
|
"children": [
|
|
272
287
|
{
|
|
273
288
|
"_name": "livestore.in-memory-db:execute",
|
|
274
289
|
"attributes": {
|
|
275
|
-
"sql.query": "
|
|
290
|
+
"sql.query": "
|
|
291
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
292
|
+
VALUES (?, ?)
|
|
293
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
294
|
+
value = json_set(json_set(value, ?, json(?)), ?, json(?))
|
|
295
|
+
",
|
|
276
296
|
},
|
|
277
297
|
},
|
|
278
298
|
],
|
|
@@ -330,7 +350,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
330
350
|
}
|
|
331
351
|
`;
|
|
332
352
|
|
|
333
|
-
exports[`
|
|
353
|
+
exports[`useClientDocument > should update the data based on component key 1`] = `
|
|
334
354
|
{
|
|
335
355
|
"atoms": [
|
|
336
356
|
{
|
|
@@ -414,7 +434,7 @@ exports[`useRow > should update the data based on component key 1`] = `
|
|
|
414
434
|
},
|
|
415
435
|
"previousResult": {
|
|
416
436
|
"_tag": "Some",
|
|
417
|
-
"value": "{"username":"","text":""
|
|
437
|
+
"value": "{"username":"","text":""}",
|
|
418
438
|
},
|
|
419
439
|
"recomputations": 1,
|
|
420
440
|
"sub": [
|
|
@@ -441,7 +461,7 @@ exports[`useRow > should update the data based on component key 1`] = `
|
|
|
441
461
|
}
|
|
442
462
|
`;
|
|
443
463
|
|
|
444
|
-
exports[`
|
|
464
|
+
exports[`useClientDocument > should update the data based on component key 2`] = `
|
|
445
465
|
{
|
|
446
466
|
"atoms": [
|
|
447
467
|
{
|
|
@@ -525,7 +545,7 @@ exports[`useRow > should update the data based on component key 2`] = `
|
|
|
525
545
|
},
|
|
526
546
|
"previousResult": {
|
|
527
547
|
"_tag": "Some",
|
|
528
|
-
"value": "{"username":"username_u2","text":""
|
|
548
|
+
"value": "{"username":"username_u2","text":""}",
|
|
529
549
|
},
|
|
530
550
|
"recomputations": 2,
|
|
531
551
|
"sub": [
|
|
@@ -84,7 +84,7 @@ exports[`useQuery (strictMode={ strictMode: false }) > filtered dependency query
|
|
|
84
84
|
},
|
|
85
85
|
"previousResult": {
|
|
86
86
|
"_tag": "Some",
|
|
87
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}
|
|
87
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}}",
|
|
88
88
|
},
|
|
89
89
|
"recomputations": 1,
|
|
90
90
|
"sub": [
|
|
@@ -234,7 +234,7 @@ exports[`useQuery (strictMode={ strictMode: false }) > filtered dependency query
|
|
|
234
234
|
},
|
|
235
235
|
"previousResult": {
|
|
236
236
|
"_tag": "Some",
|
|
237
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}
|
|
237
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}}",
|
|
238
238
|
},
|
|
239
239
|
"recomputations": 1,
|
|
240
240
|
"sub": [
|
|
@@ -384,7 +384,7 @@ exports[`useQuery (strictMode={ strictMode: false }) > filtered dependency query
|
|
|
384
384
|
},
|
|
385
385
|
"previousResult": {
|
|
386
386
|
"_tag": "Some",
|
|
387
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t2"],"queriedTables":{}
|
|
387
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t2"],"queriedTables":{}}",
|
|
388
388
|
},
|
|
389
389
|
"recomputations": 2,
|
|
390
390
|
"sub": [
|
|
@@ -561,7 +561,7 @@ exports[`useQuery (strictMode={ strictMode: false }) > same \`useQuery\` hook in
|
|
|
561
561
|
}
|
|
562
562
|
`;
|
|
563
563
|
|
|
564
|
-
exports[`useQuery (strictMode={ strictMode: false }) > same \`useQuery\` hook invoked with different queries > 2: after first
|
|
564
|
+
exports[`useQuery (strictMode={ strictMode: false }) > same \`useQuery\` hook invoked with different queries > 2: after first commit 1`] = `
|
|
565
565
|
{
|
|
566
566
|
"atoms": [
|
|
567
567
|
{
|
|
@@ -1089,7 +1089,7 @@ exports[`useQuery (strictMode={ strictMode: true }) > filtered dependency query
|
|
|
1089
1089
|
},
|
|
1090
1090
|
"previousResult": {
|
|
1091
1091
|
"_tag": "Some",
|
|
1092
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}
|
|
1092
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}}",
|
|
1093
1093
|
},
|
|
1094
1094
|
"recomputations": 1,
|
|
1095
1095
|
"sub": [
|
|
@@ -1239,7 +1239,7 @@ exports[`useQuery (strictMode={ strictMode: true }) > filtered dependency query
|
|
|
1239
1239
|
},
|
|
1240
1240
|
"previousResult": {
|
|
1241
1241
|
"_tag": "Some",
|
|
1242
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}
|
|
1242
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t1"],"queriedTables":{}}",
|
|
1243
1243
|
},
|
|
1244
1244
|
"recomputations": 1,
|
|
1245
1245
|
"sub": [
|
|
@@ -1389,7 +1389,7 @@ exports[`useQuery (strictMode={ strictMode: true }) > filtered dependency query
|
|
|
1389
1389
|
},
|
|
1390
1390
|
"previousResult": {
|
|
1391
1391
|
"_tag": "Some",
|
|
1392
|
-
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t2"],"queriedTables":{}
|
|
1392
|
+
"value": "{"query":"SELECT * FROM 'todos' WHERE id = ?","bindValues":["t2"],"queriedTables":{}}",
|
|
1393
1393
|
},
|
|
1394
1394
|
"recomputations": 2,
|
|
1395
1395
|
"sub": [
|
|
@@ -1566,7 +1566,7 @@ exports[`useQuery (strictMode={ strictMode: true }) > same \`useQuery\` hook inv
|
|
|
1566
1566
|
}
|
|
1567
1567
|
`;
|
|
1568
1568
|
|
|
1569
|
-
exports[`useQuery (strictMode={ strictMode: true }) > same \`useQuery\` hook invoked with different queries > 2: after first
|
|
1569
|
+
exports[`useQuery (strictMode={ strictMode: true }) > same \`useQuery\` hook invoked with different queries > 2: after first commit 1`] = `
|
|
1570
1570
|
{
|
|
1571
1571
|
"atoms": [
|
|
1572
1572
|
{
|