@livestore/react 0.3.0-dev.22 → 0.3.0-dev.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/LiveStoreProvider.d.ts +8 -2
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +11 -5
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +2 -2
- package/dist/useAtom.js +5 -5
- package/dist/useQuery.test.js +5 -5
- package/dist/useRow.js +7 -7
- package/dist/useRow.test.js +7 -7
- package/package.json +5 -5
- package/src/LiveStoreProvider.test.tsx +2 -2
- package/src/LiveStoreProvider.tsx +17 -6
- package/src/__snapshots__/useRow.test.tsx.snap +8 -8
- package/src/useAtom.ts +5 -5
- package/src/useQuery.test.tsx +5 -5
- package/src/useRow.test.tsx +7 -7
- package/src/useRow.ts +7 -7
- package/tmp/pack.tgz +0 -0
|
@@ -4,7 +4,7 @@ import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
|
4
4
|
import type { OtelOptions, Store } from '@livestore/livestore';
|
|
5
5
|
import { StoreInterrupted } from '@livestore/livestore';
|
|
6
6
|
import type { OtelTracer } from '@livestore/utils/effect';
|
|
7
|
-
import { Effect } from '@livestore/utils/effect';
|
|
7
|
+
import { Effect, Schema } from '@livestore/utils/effect';
|
|
8
8
|
import type * as otel from '@opentelemetry/api';
|
|
9
9
|
import type { ReactElement, ReactNode } from 'react';
|
|
10
10
|
import React from 'react';
|
|
@@ -52,8 +52,14 @@ export interface LiveStoreProviderProps {
|
|
|
52
52
|
* @default true
|
|
53
53
|
*/
|
|
54
54
|
confirmUnsavedChanges?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Payload that will be passed to the sync backend when connecting
|
|
57
|
+
*
|
|
58
|
+
* @default undefined
|
|
59
|
+
*/
|
|
60
|
+
syncPayload?: Schema.JsonValue;
|
|
55
61
|
}
|
|
56
|
-
export declare const LiveStoreProvider: ({ renderLoading, renderError, renderShutdown, otelOptions, children, schema, storeId, boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges, }: LiveStoreProviderProps & {
|
|
62
|
+
export declare const LiveStoreProvider: ({ renderLoading, renderError, renderShutdown, otelOptions, children, schema, storeId, boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges, syncPayload, }: LiveStoreProviderProps & {
|
|
57
63
|
children?: ReactNode;
|
|
58
64
|
}) => React.ReactElement;
|
|
59
65
|
//# sourceMappingURL=LiveStoreProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACxG,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAGV,WAAW,EAEX,KAAK,EACN,MAAM,sBAAsB,CAAA;AAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACxG,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAGV,WAAW,EAEX,KAAK,EACN,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAqC,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yB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oBD,eAAO,MAAM,iBAAiB,GAAI,mLAe/B,sBAAsB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,KAAK,CAAC,YAiC5D,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { provideOtel, UnexpectedError } from '@livestore/common';
|
|
2
|
-
import { createStore, StoreInterrupted } from '@livestore/livestore';
|
|
2
|
+
import { createStore, makeShutdownDeferred, StoreInterrupted } from '@livestore/livestore';
|
|
3
3
|
import { errorToString, LS_DEV } from '@livestore/utils';
|
|
4
4
|
import { Cause, Deferred, Effect, Exit, identity, Logger, LogLevel, Schema, Scope, TaskTracing, } from '@livestore/utils/effect';
|
|
5
5
|
import React from 'react';
|
|
@@ -19,7 +19,7 @@ const defaultRenderShutdown = (cause) => {
|
|
|
19
19
|
"LiveStore Shutdown due to ",
|
|
20
20
|
reason);
|
|
21
21
|
};
|
|
22
|
-
export const LiveStoreProvider = ({ renderLoading, renderError = defaultRenderError, renderShutdown = defaultRenderShutdown, otelOptions, children, schema, storeId = 'default', boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges = true, }) => {
|
|
22
|
+
export const LiveStoreProvider = ({ renderLoading, renderError = defaultRenderError, renderShutdown = defaultRenderShutdown, otelOptions, children, schema, storeId = 'default', boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges = true, syncPayload, }) => {
|
|
23
23
|
const storeCtx = useCreateStore({
|
|
24
24
|
storeId,
|
|
25
25
|
schema,
|
|
@@ -30,6 +30,7 @@ export const LiveStoreProvider = ({ renderLoading, renderError = defaultRenderEr
|
|
|
30
30
|
disableDevtools,
|
|
31
31
|
signal,
|
|
32
32
|
confirmUnsavedChanges,
|
|
33
|
+
syncPayload,
|
|
33
34
|
});
|
|
34
35
|
if (storeCtx.stage === 'error') {
|
|
35
36
|
return renderError(storeCtx.error);
|
|
@@ -56,7 +57,7 @@ const withSemaphore = (storeId) => {
|
|
|
56
57
|
}
|
|
57
58
|
return semaphore.withPermits(1);
|
|
58
59
|
};
|
|
59
|
-
const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, context, params, confirmUnsavedChanges, }) => {
|
|
60
|
+
const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, context, params, confirmUnsavedChanges, syncPayload, }) => {
|
|
60
61
|
const [_, rerender] = React.useState(0);
|
|
61
62
|
const ctxValueRef = React.useRef({
|
|
62
63
|
value: { stage: 'loading' },
|
|
@@ -76,6 +77,7 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
76
77
|
context,
|
|
77
78
|
params,
|
|
78
79
|
confirmUnsavedChanges,
|
|
80
|
+
syncPayload,
|
|
79
81
|
});
|
|
80
82
|
const interrupt = (componentScope, shutdownDeferred, error) => Effect.gen(function* () {
|
|
81
83
|
// console.log('[@livestore/livestore/react] interupting', error)
|
|
@@ -91,7 +93,8 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
91
93
|
inputPropsCacheRef.current.signal !== signal ||
|
|
92
94
|
inputPropsCacheRef.current.context !== context ||
|
|
93
95
|
inputPropsCacheRef.current.params !== params ||
|
|
94
|
-
inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges
|
|
96
|
+
inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges ||
|
|
97
|
+
inputPropsCacheRef.current.syncPayload !== syncPayload) {
|
|
95
98
|
inputPropsCacheRef.current = {
|
|
96
99
|
schema,
|
|
97
100
|
otelOptions,
|
|
@@ -103,6 +106,7 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
103
106
|
context,
|
|
104
107
|
params,
|
|
105
108
|
confirmUnsavedChanges,
|
|
109
|
+
syncPayload,
|
|
106
110
|
};
|
|
107
111
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
108
112
|
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 're-rendering due to changed input props' }));
|
|
@@ -135,7 +139,7 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
135
139
|
});
|
|
136
140
|
Effect.gen(function* () {
|
|
137
141
|
const componentScope = yield* Scope.make();
|
|
138
|
-
const shutdownDeferred = yield*
|
|
142
|
+
const shutdownDeferred = yield* makeShutdownDeferred;
|
|
139
143
|
ctxValueRef.current.componentScope = componentScope;
|
|
140
144
|
ctxValueRef.current.shutdownDeferred = shutdownDeferred;
|
|
141
145
|
yield* Effect.gen(function* () {
|
|
@@ -150,6 +154,7 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
150
154
|
context,
|
|
151
155
|
params,
|
|
152
156
|
confirmUnsavedChanges,
|
|
157
|
+
syncPayload,
|
|
153
158
|
onBootStatus: (status) => {
|
|
154
159
|
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
|
|
155
160
|
return;
|
|
@@ -185,6 +190,7 @@ const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpda
|
|
|
185
190
|
context,
|
|
186
191
|
params,
|
|
187
192
|
confirmUnsavedChanges,
|
|
193
|
+
syncPayload,
|
|
188
194
|
]);
|
|
189
195
|
return ctxValueRef.current.value;
|
|
190
196
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAShE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAA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oreProvider', () => {
|
|
|
21
21
|
};
|
|
22
22
|
const abortController = new AbortController();
|
|
23
23
|
const Root = ({ forceUpdate }) => {
|
|
24
|
-
const bootCb = React.useCallback((store) => store.
|
|
24
|
+
const bootCb = React.useCallback((store) => store.commit(rawSqlMutation({
|
|
25
25
|
sql: sql `INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
26
26
|
})), []);
|
|
27
27
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -50,7 +50,7 @@ describe('LiveStoreProvider', () => {
|
|
|
50
50
|
return React.createElement("div", null, "hello world");
|
|
51
51
|
};
|
|
52
52
|
const Root = ({ forceUpdate }) => {
|
|
53
|
-
const bootCb = React.useCallback((store) => store.
|
|
53
|
+
const bootCb = React.useCallback((store) => store.commit(rawSqlMutation({
|
|
54
54
|
sql: sql `INSERT OR IGNORE INTO todos_missing_table (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
55
55
|
})), []);
|
|
56
56
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/dist/useAtom.js
CHANGED
|
@@ -16,21 +16,21 @@ export const useAtom = (queryDef, options) => {
|
|
|
16
16
|
const table = query$.queryInfo.table;
|
|
17
17
|
if (query$.queryInfo._tag === 'Row') {
|
|
18
18
|
if (table.options.isSingleton && table.options.isSingleColumn) {
|
|
19
|
-
store.
|
|
19
|
+
store.commit(table.update(newValue));
|
|
20
20
|
}
|
|
21
21
|
else if (table.options.isSingleColumn) {
|
|
22
|
-
store.
|
|
22
|
+
store.commit(table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }));
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
store.
|
|
25
|
+
store.commit(table.update({ where: { id: query$.queryInfo.id }, values: newValue }));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
if (table.options.isSingleton && table.options.isSingleColumn) {
|
|
30
|
-
store.
|
|
30
|
+
store.commit(table.update({ [query$.queryInfo.column]: newValue }));
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
store.
|
|
33
|
+
store.commit(table.update({
|
|
34
34
|
where: { id: query$.queryInfo.id },
|
|
35
35
|
values: { [query$.queryInfo.column]: newValue },
|
|
36
36
|
}));
|
package/dist/useQuery.test.js
CHANGED
|
@@ -27,7 +27,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
27
27
|
expect(renderCount.val).toBe(1);
|
|
28
28
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
29
29
|
console.log('before mutation');
|
|
30
|
-
ReactTesting.act(() => store.
|
|
30
|
+
ReactTesting.act(() => store.commit(todos.insert({ id: 't1', text: 'buy milk', completed: false })));
|
|
31
31
|
console.log('after mutation');
|
|
32
32
|
expect(result.current.length).toBe(1);
|
|
33
33
|
expect(result.current[0].text).toBe('buy milk');
|
|
@@ -38,7 +38,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
38
38
|
const { wrapper, store, renderCount } = yield* makeTodoMvcReact({ strictMode });
|
|
39
39
|
const todo1$ = queryDb({ query: `select * from todos where id = 't1'`, schema: Schema.Array(tables.todos.schema) }, { label: 'libraryTracksView1' });
|
|
40
40
|
const todo2$ = queryDb({ query: `select * from todos where id = 't2'`, schema: Schema.Array(tables.todos.schema) }, { label: 'libraryTracksView2' });
|
|
41
|
-
store.
|
|
41
|
+
store.commit(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy eggs', completed: false }));
|
|
42
42
|
const { result, rerender } = ReactTesting.renderHook((todoId) => {
|
|
43
43
|
renderCount.inc();
|
|
44
44
|
const query$ = React.useMemo(() => (todoId === 't1' ? todo1$ : todo2$), [todoId]);
|
|
@@ -47,7 +47,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
47
47
|
expect(result.current).toBe('buy milk');
|
|
48
48
|
expect(renderCount.val).toBe(1);
|
|
49
49
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('1: after first render');
|
|
50
|
-
ReactTesting.act(() => store.
|
|
50
|
+
ReactTesting.act(() => store.commit(todos.update({ where: { id: 't1' }, values: { text: 'buy soy milk' } })));
|
|
51
51
|
expect(result.current).toBe('buy soy milk');
|
|
52
52
|
expect(renderCount.val).toBe(2);
|
|
53
53
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('2: after first mutation');
|
|
@@ -60,7 +60,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
60
60
|
const { wrapper, store, renderCount } = yield* makeTodoMvcReact({ strictMode });
|
|
61
61
|
const filter$ = makeRef('t1', { label: 'id-filter' });
|
|
62
62
|
const todo$ = queryDb((get) => tables.todos.query.where('id', get(filter$)), { label: 'todo' });
|
|
63
|
-
store.
|
|
63
|
+
store.commit(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy eggs', completed: false }));
|
|
64
64
|
const { result } = ReactTesting.renderHook(() => {
|
|
65
65
|
renderCount.inc();
|
|
66
66
|
return LiveStoreReact.useQuery(todo$)[0].text;
|
|
@@ -68,7 +68,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }])('useQuery (s
|
|
|
68
68
|
expect(result.current).toBe('buy milk');
|
|
69
69
|
expect(renderCount.val).toBe(1);
|
|
70
70
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
71
|
-
ReactTesting.act(() => store.
|
|
71
|
+
ReactTesting.act(() => store.commit(todos.update({ where: { id: 't1' }, values: { text: 'buy soy milk' } })));
|
|
72
72
|
expect(result.current).toBe('buy soy milk');
|
|
73
73
|
expect(renderCount.val).toBe(2);
|
|
74
74
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
package/dist/useRow.js
CHANGED
|
@@ -57,12 +57,12 @@ export const useRow = (table, idOrOptions, options_) => {
|
|
|
57
57
|
return;
|
|
58
58
|
// NOTE we need to account for the short-hand syntax for single-column+singleton tables
|
|
59
59
|
if (table.options.isSingleton) {
|
|
60
|
-
store.
|
|
60
|
+
store.commit(table.update(newValue));
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
store.
|
|
63
|
+
store.commit(table.update({ where: { id }, values: { value: newValue } }));
|
|
64
64
|
}
|
|
65
|
-
// store.
|
|
65
|
+
// store.commit(updateMutationForQueryInfo(query$.queryInfo!, { value: newValue }))
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
@@ -75,8 +75,8 @@ export const useRow = (table, idOrOptions, options_) => {
|
|
|
75
75
|
// @ts-expect-error TODO fix typing
|
|
76
76
|
if (queryRef.valueRef.current[columnName] === newValue)
|
|
77
77
|
return;
|
|
78
|
-
store.
|
|
79
|
-
// store.
|
|
78
|
+
store.commit(table.update({ where: { id: id ?? 'singleton' }, values: { [columnName]: newValue } }));
|
|
79
|
+
// store.commit(updateMutationForQueryInfo(query$.queryInfo!, { [columnName]: newValue }))
|
|
80
80
|
});
|
|
81
81
|
setState.setMany = (columnValuesOrFn) => {
|
|
82
82
|
const columnValues =
|
|
@@ -89,8 +89,8 @@ export const useRow = (table, idOrOptions, options_) => {
|
|
|
89
89
|
Object.entries(columnValues).every(([columnName, value]) => queryRef.valueRef.current[columnName] === value)) {
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
store.
|
|
93
|
-
// store.
|
|
92
|
+
store.commit(table.update({ where: { id: id ?? 'singleton' }, values: columnValues }));
|
|
93
|
+
// store.commit(updateMutationForQueryInfo(query$.queryInfo!, columnValues))
|
|
94
94
|
};
|
|
95
95
|
return setState;
|
|
96
96
|
}
|
package/dist/useRow.test.js
CHANGED
|
@@ -27,7 +27,7 @@ Vitest.describe('useRow', () => {
|
|
|
27
27
|
expect(result.current.state.username).toBe('');
|
|
28
28
|
expect(renderCount.val).toBe(1);
|
|
29
29
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
30
|
-
store.
|
|
30
|
+
store.commit(tables.userInfo.insert({ id: 'u2', username: 'username_u2' }));
|
|
31
31
|
rerender('u2');
|
|
32
32
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot();
|
|
33
33
|
expect(result.current.state.id).toBe('u2');
|
|
@@ -60,7 +60,7 @@ Vitest.describe('useRow', () => {
|
|
|
60
60
|
expect(result.current.state.id).toBe('u1');
|
|
61
61
|
expect(result.current.state.username).toBe('');
|
|
62
62
|
expect(renderCount.val).toBe(1);
|
|
63
|
-
ReactTesting.act(() => store.
|
|
63
|
+
ReactTesting.act(() => store.commit(tables.userInfo.update({ where: { id: 'u1' }, values: { username: 'username_u1_hello' } })));
|
|
64
64
|
expect(result.current.state.id).toBe('u1');
|
|
65
65
|
expect(result.current.state.username).toBe('username_u1_hello');
|
|
66
66
|
expect(renderCount.val).toBe(2);
|
|
@@ -90,7 +90,7 @@ Vitest.describe('useRow', () => {
|
|
|
90
90
|
};
|
|
91
91
|
const renderResult = ReactTesting.render(React.createElement(AppRouter, null), { wrapper });
|
|
92
92
|
expect(renderCount.val).toBe(1);
|
|
93
|
-
ReactTesting.act(() => store.
|
|
93
|
+
ReactTesting.act(() => store.commit(LiveStore.rawSqlMutation({
|
|
94
94
|
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
95
95
|
})));
|
|
96
96
|
expect(renderCount.val).toBe(1);
|
|
@@ -99,7 +99,7 @@ Vitest.describe('useRow', () => {
|
|
|
99
99
|
expect(renderCount.val).toBe(2);
|
|
100
100
|
expect(renderResult.getByRole('content').innerHTML).toMatchInlineSnapshot(`"{"id":"t1","text":"buy milk","completed":false}"`);
|
|
101
101
|
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t1"');
|
|
102
|
-
ReactTesting.act(() => store.
|
|
102
|
+
ReactTesting.act(() => store.commit(LiveStore.rawSqlMutation({
|
|
103
103
|
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t2', 'buy eggs', 0)`,
|
|
104
104
|
}), AppRouterSchema.update({ where: { id: 'singleton' }, values: { currentTaskId: 't2' } }), LiveStore.rawSqlMutation({
|
|
105
105
|
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t3', 'buy bread', 0)`,
|
|
@@ -109,7 +109,7 @@ Vitest.describe('useRow', () => {
|
|
|
109
109
|
}));
|
|
110
110
|
Vitest.scopedLive('should work for a useRow query chained with a useTemporary query', () => Effect.gen(function* () {
|
|
111
111
|
const { store, wrapper, renderCount } = yield* makeTodoMvcReact({});
|
|
112
|
-
store.
|
|
112
|
+
store.commit(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy bread', completed: false }));
|
|
113
113
|
const { result, unmount, rerender } = ReactTesting.renderHook((userId) => {
|
|
114
114
|
renderCount.inc();
|
|
115
115
|
const [_row, _setRow, rowState$] = LiveStoreReact.useRow(tables.userInfo, userId);
|
|
@@ -119,7 +119,7 @@ Vitest.describe('useRow', () => {
|
|
|
119
119
|
{ label: 'todosFiltered', deps: userId }));
|
|
120
120
|
return { todos };
|
|
121
121
|
}, { wrapper, initialProps: 'u1' });
|
|
122
|
-
ReactTesting.act(() => store.
|
|
122
|
+
ReactTesting.act(() => store.commit(tables.userInfo.insert({ id: 'u2', username: 'username_u2', text: 'milk' })));
|
|
123
123
|
expect(result.current.todos.length).toBe(2);
|
|
124
124
|
expect(renderCount.val).toBe(1);
|
|
125
125
|
rerender('u2');
|
|
@@ -153,7 +153,7 @@ Vitest.describe('useRow', () => {
|
|
|
153
153
|
expect(renderCount.val).toBe(1);
|
|
154
154
|
// For u2 we'll make sure that the row already exists,
|
|
155
155
|
// so the lazy `insert` will be skipped
|
|
156
|
-
ReactTesting.act(() => store.
|
|
156
|
+
ReactTesting.act(() => store.commit(tables.userInfo.insert({ id: 'u2', username: 'username_u2' })));
|
|
157
157
|
rerender('u2');
|
|
158
158
|
expect(result.current.state.id).toBe('u2');
|
|
159
159
|
expect(result.current.state.username).toBe('username_u2');
|
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.24",
|
|
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.3.0-dev.
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/
|
|
26
|
+
"@livestore/common": "0.3.0-dev.24",
|
|
27
|
+
"@livestore/livestore": "0.3.0-dev.24",
|
|
28
|
+
"@livestore/utils": "0.3.0-dev.24"
|
|
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.3.0-dev.
|
|
43
|
+
"@livestore/adapter-web": "0.3.0-dev.24"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "~19.0.0"
|
|
@@ -31,7 +31,7 @@ describe('LiveStoreProvider', () => {
|
|
|
31
31
|
const Root = ({ forceUpdate }: { forceUpdate: number }) => {
|
|
32
32
|
const bootCb = React.useCallback(
|
|
33
33
|
(store: Store) =>
|
|
34
|
-
store.
|
|
34
|
+
store.commit(
|
|
35
35
|
rawSqlMutation({
|
|
36
36
|
sql: sql`INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
37
37
|
}),
|
|
@@ -88,7 +88,7 @@ describe('LiveStoreProvider', () => {
|
|
|
88
88
|
const Root = ({ forceUpdate }: { forceUpdate: number }) => {
|
|
89
89
|
const bootCb = React.useCallback(
|
|
90
90
|
(store: Store) =>
|
|
91
|
-
store.
|
|
91
|
+
store.commit(
|
|
92
92
|
rawSqlMutation({
|
|
93
93
|
sql: sql`INSERT OR IGNORE INTO todos_missing_table (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
94
94
|
}),
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
ShutdownDeferred,
|
|
9
9
|
Store,
|
|
10
10
|
} from '@livestore/livestore'
|
|
11
|
-
import { createStore, StoreInterrupted } from '@livestore/livestore'
|
|
11
|
+
import { createStore, makeShutdownDeferred, StoreInterrupted } from '@livestore/livestore'
|
|
12
12
|
import { errorToString, LS_DEV } from '@livestore/utils'
|
|
13
13
|
import type { OtelTracer } from '@livestore/utils/effect'
|
|
14
14
|
import {
|
|
@@ -73,6 +73,12 @@ export interface LiveStoreProviderProps {
|
|
|
73
73
|
* @default true
|
|
74
74
|
*/
|
|
75
75
|
confirmUnsavedChanges?: boolean
|
|
76
|
+
/**
|
|
77
|
+
* Payload that will be passed to the sync backend when connecting
|
|
78
|
+
*
|
|
79
|
+
* @default undefined
|
|
80
|
+
*/
|
|
81
|
+
syncPayload?: Schema.JsonValue
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
const defaultRenderError = (error: UnexpectedError | unknown) => (
|
|
@@ -107,6 +113,7 @@ export const LiveStoreProvider = ({
|
|
|
107
113
|
disableDevtools,
|
|
108
114
|
signal,
|
|
109
115
|
confirmUnsavedChanges = true,
|
|
116
|
+
syncPayload,
|
|
110
117
|
}: LiveStoreProviderProps & { children?: ReactNode }): React.ReactElement => {
|
|
111
118
|
const storeCtx = useCreateStore({
|
|
112
119
|
storeId,
|
|
@@ -118,6 +125,7 @@ export const LiveStoreProvider = ({
|
|
|
118
125
|
disableDevtools,
|
|
119
126
|
signal,
|
|
120
127
|
confirmUnsavedChanges,
|
|
128
|
+
syncPayload,
|
|
121
129
|
})
|
|
122
130
|
|
|
123
131
|
if (storeCtx.stage === 'error') {
|
|
@@ -165,6 +173,7 @@ const useCreateStore = ({
|
|
|
165
173
|
context,
|
|
166
174
|
params,
|
|
167
175
|
confirmUnsavedChanges,
|
|
176
|
+
syncPayload,
|
|
168
177
|
}: CreateStoreOptions<LiveStoreSchema> & {
|
|
169
178
|
signal?: AbortSignal
|
|
170
179
|
otelOptions?: Partial<OtelOptions>
|
|
@@ -195,6 +204,7 @@ const useCreateStore = ({
|
|
|
195
204
|
context,
|
|
196
205
|
params,
|
|
197
206
|
confirmUnsavedChanges,
|
|
207
|
+
syncPayload,
|
|
198
208
|
})
|
|
199
209
|
|
|
200
210
|
const interrupt = (
|
|
@@ -221,7 +231,8 @@ const useCreateStore = ({
|
|
|
221
231
|
inputPropsCacheRef.current.signal !== signal ||
|
|
222
232
|
inputPropsCacheRef.current.context !== context ||
|
|
223
233
|
inputPropsCacheRef.current.params !== params ||
|
|
224
|
-
inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges
|
|
234
|
+
inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges ||
|
|
235
|
+
inputPropsCacheRef.current.syncPayload !== syncPayload
|
|
225
236
|
) {
|
|
226
237
|
inputPropsCacheRef.current = {
|
|
227
238
|
schema,
|
|
@@ -234,6 +245,7 @@ const useCreateStore = ({
|
|
|
234
245
|
context,
|
|
235
246
|
params,
|
|
236
247
|
confirmUnsavedChanges,
|
|
248
|
+
syncPayload,
|
|
237
249
|
}
|
|
238
250
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
239
251
|
interrupt(
|
|
@@ -279,10 +291,7 @@ const useCreateStore = ({
|
|
|
279
291
|
|
|
280
292
|
Effect.gen(function* () {
|
|
281
293
|
const componentScope = yield* Scope.make()
|
|
282
|
-
const shutdownDeferred = yield*
|
|
283
|
-
void,
|
|
284
|
-
UnexpectedError | IntentionalShutdownCause | StoreInterrupted
|
|
285
|
-
>()
|
|
294
|
+
const shutdownDeferred = yield* makeShutdownDeferred
|
|
286
295
|
|
|
287
296
|
ctxValueRef.current.componentScope = componentScope
|
|
288
297
|
ctxValueRef.current.shutdownDeferred = shutdownDeferred
|
|
@@ -299,6 +308,7 @@ const useCreateStore = ({
|
|
|
299
308
|
context,
|
|
300
309
|
params,
|
|
301
310
|
confirmUnsavedChanges,
|
|
311
|
+
syncPayload,
|
|
302
312
|
onBootStatus: (status) => {
|
|
303
313
|
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error') return
|
|
304
314
|
// NOTE sometimes when status come in in rapid succession, only the last value will be rendered by React
|
|
@@ -359,6 +369,7 @@ const useCreateStore = ({
|
|
|
359
369
|
context,
|
|
360
370
|
params,
|
|
361
371
|
confirmUnsavedChanges,
|
|
372
|
+
syncPayload,
|
|
362
373
|
])
|
|
363
374
|
|
|
364
375
|
return ctxValueRef.current.value
|
|
@@ -27,7 +27,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
27
27
|
"_name": "LiveStore:mutations",
|
|
28
28
|
"children": [
|
|
29
29
|
{
|
|
30
|
-
"_name": "LiveStore:
|
|
30
|
+
"_name": "LiveStore:commit",
|
|
31
31
|
"attributes": {
|
|
32
32
|
"livestore.mutationEventTags": [
|
|
33
33
|
"_Derived_Create_UserInfo",
|
|
@@ -64,9 +64,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
64
64
|
},
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
|
-
"_name": "LiveStore:
|
|
67
|
+
"_name": "LiveStore:commit",
|
|
68
68
|
"attributes": {
|
|
69
|
-
"livestore.
|
|
69
|
+
"livestore.commitLabel": "rowQuery:UserInfo:u1",
|
|
70
70
|
"livestore.mutationEventTags": [
|
|
71
71
|
"_Derived_Create_UserInfo",
|
|
72
72
|
],
|
|
@@ -109,7 +109,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
109
109
|
{
|
|
110
110
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
111
111
|
"attributes": {
|
|
112
|
-
"livestore.debugRefreshReason": "
|
|
112
|
+
"livestore.debugRefreshReason": "commit",
|
|
113
113
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
114
114
|
"sql.rowsCount": 1,
|
|
115
115
|
},
|
|
@@ -223,7 +223,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
223
223
|
"_name": "LiveStore:mutations",
|
|
224
224
|
"children": [
|
|
225
225
|
{
|
|
226
|
-
"_name": "LiveStore:
|
|
226
|
+
"_name": "LiveStore:commit",
|
|
227
227
|
"attributes": {
|
|
228
228
|
"livestore.mutationEventTags": [
|
|
229
229
|
"_Derived_Create_UserInfo",
|
|
@@ -260,9 +260,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
260
260
|
},
|
|
261
261
|
},
|
|
262
262
|
{
|
|
263
|
-
"_name": "LiveStore:
|
|
263
|
+
"_name": "LiveStore:commit",
|
|
264
264
|
"attributes": {
|
|
265
|
-
"livestore.
|
|
265
|
+
"livestore.commitLabel": "rowQuery:UserInfo:u1",
|
|
266
266
|
"livestore.mutationEventTags": [
|
|
267
267
|
"_Derived_Create_UserInfo",
|
|
268
268
|
],
|
|
@@ -305,7 +305,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
305
305
|
{
|
|
306
306
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
307
307
|
"attributes": {
|
|
308
|
-
"livestore.debugRefreshReason": "
|
|
308
|
+
"livestore.debugRefreshReason": "commit",
|
|
309
309
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
310
310
|
"sql.rowsCount": 1,
|
|
311
311
|
},
|
package/src/useAtom.ts
CHANGED
|
@@ -40,17 +40,17 @@ export const useAtom = <
|
|
|
40
40
|
|
|
41
41
|
if (query$.queryInfo._tag === 'Row') {
|
|
42
42
|
if (table.options.isSingleton && table.options.isSingleColumn) {
|
|
43
|
-
store.
|
|
43
|
+
store.commit(table.update(newValue))
|
|
44
44
|
} else if (table.options.isSingleColumn) {
|
|
45
|
-
store.
|
|
45
|
+
store.commit(table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }))
|
|
46
46
|
} else {
|
|
47
|
-
store.
|
|
47
|
+
store.commit(table.update({ where: { id: query$.queryInfo.id }, values: newValue }))
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
50
|
if (table.options.isSingleton && table.options.isSingleColumn) {
|
|
51
|
-
store.
|
|
51
|
+
store.commit(table.update({ [query$.queryInfo.column]: newValue }))
|
|
52
52
|
} else {
|
|
53
|
-
store.
|
|
53
|
+
store.commit(
|
|
54
54
|
table.update({
|
|
55
55
|
where: { id: query$.queryInfo.id },
|
|
56
56
|
values: { [query$.queryInfo.column]: newValue },
|
package/src/useQuery.test.tsx
CHANGED
|
@@ -42,7 +42,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
42
42
|
|
|
43
43
|
console.log('before mutation')
|
|
44
44
|
|
|
45
|
-
ReactTesting.act(() => store.
|
|
45
|
+
ReactTesting.act(() => store.commit(todos.insert({ id: 't1', text: 'buy milk', completed: false })))
|
|
46
46
|
|
|
47
47
|
console.log('after mutation')
|
|
48
48
|
|
|
@@ -66,7 +66,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
66
66
|
{ label: 'libraryTracksView2' },
|
|
67
67
|
)
|
|
68
68
|
|
|
69
|
-
store.
|
|
69
|
+
store.commit(
|
|
70
70
|
todos.insert({ id: 't1', text: 'buy milk', completed: false }),
|
|
71
71
|
todos.insert({ id: 't2', text: 'buy eggs', completed: false }),
|
|
72
72
|
)
|
|
@@ -86,7 +86,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
86
86
|
expect(renderCount.val).toBe(1)
|
|
87
87
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot('1: after first render')
|
|
88
88
|
|
|
89
|
-
ReactTesting.act(() => store.
|
|
89
|
+
ReactTesting.act(() => store.commit(todos.update({ where: { id: 't1' }, values: { text: 'buy soy milk' } })))
|
|
90
90
|
|
|
91
91
|
expect(result.current).toBe('buy soy milk')
|
|
92
92
|
expect(renderCount.val).toBe(2)
|
|
@@ -108,7 +108,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
108
108
|
|
|
109
109
|
const todo$ = queryDb((get) => tables.todos.query.where('id', get(filter$)), { label: 'todo' })
|
|
110
110
|
|
|
111
|
-
store.
|
|
111
|
+
store.commit(
|
|
112
112
|
todos.insert({ id: 't1', text: 'buy milk', completed: false }),
|
|
113
113
|
todos.insert({ id: 't2', text: 'buy eggs', completed: false }),
|
|
114
114
|
)
|
|
@@ -126,7 +126,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
126
126
|
expect(renderCount.val).toBe(1)
|
|
127
127
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
|
|
128
128
|
|
|
129
|
-
ReactTesting.act(() => store.
|
|
129
|
+
ReactTesting.act(() => store.commit(todos.update({ where: { id: 't1' }, values: { text: 'buy soy milk' } })))
|
|
130
130
|
|
|
131
131
|
expect(result.current).toBe('buy soy milk')
|
|
132
132
|
expect(renderCount.val).toBe(2)
|