@livestore/react 0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df
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/README.md +1 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/LiveStoreContext.d.ts +7 -0
- package/dist/LiveStoreContext.d.ts.map +1 -0
- package/dist/LiveStoreContext.js +13 -0
- package/dist/LiveStoreContext.js.map +1 -0
- package/dist/LiveStoreProvider.d.ts +49 -0
- package/dist/LiveStoreProvider.d.ts.map +1 -0
- package/dist/LiveStoreProvider.js +168 -0
- package/dist/LiveStoreProvider.js.map +1 -0
- package/dist/LiveStoreProvider.test.d.ts +2 -0
- package/dist/LiveStoreProvider.test.d.ts.map +1 -0
- package/dist/LiveStoreProvider.test.js +62 -0
- package/dist/LiveStoreProvider.test.js.map +1 -0
- package/dist/__tests__/fixture.d.ts +567 -0
- package/dist/__tests__/fixture.d.ts.map +1 -0
- package/dist/__tests__/fixture.js +61 -0
- package/dist/__tests__/fixture.js.map +1 -0
- package/dist/experimental/components/LiveList.d.ts +21 -0
- package/dist/experimental/components/LiveList.d.ts.map +1 -0
- package/dist/experimental/components/LiveList.js +31 -0
- package/dist/experimental/components/LiveList.js.map +1 -0
- package/dist/experimental/mod.d.ts +2 -0
- package/dist/experimental/mod.d.ts.map +1 -0
- package/dist/experimental/mod.js +2 -0
- package/dist/experimental/mod.js.map +1 -0
- package/dist/mod.d.ts +8 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +8 -0
- package/dist/mod.js.map +1 -0
- package/dist/useAtom.d.ts +10 -0
- package/dist/useAtom.d.ts.map +1 -0
- package/dist/useAtom.js +37 -0
- package/dist/useAtom.js.map +1 -0
- package/dist/useQuery.d.ts +9 -0
- package/dist/useQuery.d.ts.map +1 -0
- package/dist/useQuery.js +88 -0
- package/dist/useQuery.js.map +1 -0
- package/dist/useQuery.test.d.ts +2 -0
- package/dist/useQuery.test.d.ts.map +1 -0
- package/dist/useQuery.test.js +51 -0
- package/dist/useQuery.test.js.map +1 -0
- package/dist/useRow.d.ts +46 -0
- package/dist/useRow.d.ts.map +1 -0
- package/dist/useRow.js +96 -0
- package/dist/useRow.js.map +1 -0
- package/dist/useRow.test.d.ts +2 -0
- package/dist/useRow.test.d.ts.map +1 -0
- package/dist/useRow.test.js +212 -0
- package/dist/useRow.test.js.map +1 -0
- package/dist/useTemporaryQuery.d.ts +22 -0
- package/dist/useTemporaryQuery.d.ts.map +1 -0
- package/dist/useTemporaryQuery.js +75 -0
- package/dist/useTemporaryQuery.js.map +1 -0
- package/dist/useTemporaryQuery.test.d.ts +2 -0
- package/dist/useTemporaryQuery.test.d.ts.map +1 -0
- package/dist/useTemporaryQuery.test.js +59 -0
- package/dist/useTemporaryQuery.test.js.map +1 -0
- package/dist/utils/stack-info.d.ts +4 -0
- package/dist/utils/stack-info.d.ts.map +1 -0
- package/dist/utils/stack-info.js +11 -0
- package/dist/utils/stack-info.js.map +1 -0
- package/dist/utils/useStateRefWithReactiveInput.d.ts +13 -0
- package/dist/utils/useStateRefWithReactiveInput.d.ts.map +1 -0
- package/dist/utils/useStateRefWithReactiveInput.js +38 -0
- package/dist/utils/useStateRefWithReactiveInput.js.map +1 -0
- package/package.json +54 -0
- package/src/LiveStoreContext.ts +19 -0
- package/src/LiveStoreProvider.test.tsx +109 -0
- package/src/LiveStoreProvider.tsx +295 -0
- package/src/__snapshots__/useRow.test.tsx.snap +359 -0
- package/src/__tests__/fixture.tsx +119 -0
- package/src/ambient.d.ts +2 -0
- package/src/experimental/components/LiveList.tsx +84 -0
- package/src/experimental/mod.ts +1 -0
- package/src/mod.ts +13 -0
- package/src/useAtom.ts +55 -0
- package/src/useQuery.test.tsx +82 -0
- package/src/useQuery.ts +122 -0
- package/src/useRow.test.tsx +346 -0
- package/src/useRow.ts +182 -0
- package/src/useTemporaryQuery.test.tsx +98 -0
- package/src/useTemporaryQuery.ts +131 -0
- package/src/utils/stack-info.ts +13 -0
- package/src/utils/useStateRefWithReactiveInput.ts +51 -0
- package/tsconfig.json +20 -0
- package/vitest.config.js +17 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as LiveStore from '@livestore/livestore';
|
|
2
|
+
import { getSimplifiedRootSpan } from '@livestore/livestore/internal/testing-utils';
|
|
3
|
+
import { Effect, ReadonlyRecord, Schema } from '@livestore/utils/effect';
|
|
4
|
+
import * as otel from '@opentelemetry/api';
|
|
5
|
+
import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
6
|
+
import { render, renderHook } from '@testing-library/react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { AppComponentSchema, AppRouterSchema, makeTodoMvcReact, tables, todos } from './__tests__/fixture.js';
|
|
10
|
+
import * as LiveStoreReact from './mod.js';
|
|
11
|
+
// NOTE running tests concurrently doesn't work with the default global db graph
|
|
12
|
+
describe('useRow', () => {
|
|
13
|
+
it('should update the data based on component key', () => Effect.gen(function* () {
|
|
14
|
+
const { wrapper, store, reactivityGraph, makeRenderCount } = yield* makeTodoMvcReact({
|
|
15
|
+
useGlobalReactivityGraph: false,
|
|
16
|
+
});
|
|
17
|
+
const renderCount = makeRenderCount();
|
|
18
|
+
const { result, rerender } = renderHook((userId) => {
|
|
19
|
+
renderCount.inc();
|
|
20
|
+
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph });
|
|
21
|
+
return { state, setState };
|
|
22
|
+
}, { wrapper, initialProps: 'u1' });
|
|
23
|
+
expect(result.current.state.id).toBe('u1');
|
|
24
|
+
expect(result.current.state.username).toBe('');
|
|
25
|
+
expect(renderCount.val).toBe(1);
|
|
26
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
27
|
+
sql: LiveStore.sql `INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')`,
|
|
28
|
+
})));
|
|
29
|
+
rerender('u2');
|
|
30
|
+
expect(result.current.state.id).toBe('u2');
|
|
31
|
+
expect(result.current.state.username).toBe('username_u2');
|
|
32
|
+
expect(renderCount.val).toBe(2);
|
|
33
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
34
|
+
// TODO add a test that makes sure React doesn't re-render when a setter is used to set the same value
|
|
35
|
+
it('should update the data reactively - via setState', () => Effect.gen(function* () {
|
|
36
|
+
const { wrapper, reactivityGraph, makeRenderCount } = yield* makeTodoMvcReact({
|
|
37
|
+
useGlobalReactivityGraph: false,
|
|
38
|
+
});
|
|
39
|
+
const renderCount = makeRenderCount();
|
|
40
|
+
const { result } = renderHook((userId) => {
|
|
41
|
+
renderCount.inc();
|
|
42
|
+
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph });
|
|
43
|
+
return { state, setState };
|
|
44
|
+
}, { wrapper, initialProps: 'u1' });
|
|
45
|
+
expect(result.current.state.id).toBe('u1');
|
|
46
|
+
expect(result.current.state.username).toBe('');
|
|
47
|
+
expect(renderCount.val).toBe(1);
|
|
48
|
+
React.act(() => result.current.setState.username('username_u1_hello'));
|
|
49
|
+
expect(result.current.state.id).toBe('u1');
|
|
50
|
+
expect(result.current.state.username).toBe('username_u1_hello');
|
|
51
|
+
expect(renderCount.val).toBe(2);
|
|
52
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
53
|
+
it('should update the data reactively - via raw store mutation', () => Effect.gen(function* () {
|
|
54
|
+
const { wrapper, store, reactivityGraph, makeRenderCount } = yield* makeTodoMvcReact({
|
|
55
|
+
useGlobalReactivityGraph: false,
|
|
56
|
+
});
|
|
57
|
+
const renderCount = makeRenderCount();
|
|
58
|
+
const { result } = renderHook((userId) => {
|
|
59
|
+
renderCount.inc();
|
|
60
|
+
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph });
|
|
61
|
+
return { state, setState };
|
|
62
|
+
}, { wrapper, initialProps: 'u1' });
|
|
63
|
+
expect(result.current.state.id).toBe('u1');
|
|
64
|
+
expect(result.current.state.username).toBe('');
|
|
65
|
+
expect(renderCount.val).toBe(1);
|
|
66
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
67
|
+
sql: LiveStore.sql `UPDATE UserInfo SET username = 'username_u1_hello' WHERE id = 'u1';`,
|
|
68
|
+
})));
|
|
69
|
+
expect(result.current.state.id).toBe('u1');
|
|
70
|
+
expect(result.current.state.username).toBe('username_u1_hello');
|
|
71
|
+
expect(renderCount.val).toBe(2);
|
|
72
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
73
|
+
it('should work for a larger app', () => Effect.gen(function* () {
|
|
74
|
+
const { wrapper, store, reactivityGraph, makeRenderCount } = yield* makeTodoMvcReact({
|
|
75
|
+
useGlobalReactivityGraph: false,
|
|
76
|
+
});
|
|
77
|
+
const allTodos$ = LiveStore.querySQL(`select * from todos`, {
|
|
78
|
+
label: 'allTodos',
|
|
79
|
+
schema: Schema.Array(tables.todos.schema),
|
|
80
|
+
reactivityGraph,
|
|
81
|
+
});
|
|
82
|
+
const appRouterRenderCount = makeRenderCount();
|
|
83
|
+
let globalSetState;
|
|
84
|
+
const AppRouter = () => {
|
|
85
|
+
appRouterRenderCount.inc();
|
|
86
|
+
const [state, setState] = LiveStoreReact.useRow(AppRouterSchema, { reactivityGraph });
|
|
87
|
+
globalSetState = setState;
|
|
88
|
+
return (React.createElement("div", null,
|
|
89
|
+
React.createElement(TasksList, { setTaskId: setState.currentTaskId }),
|
|
90
|
+
React.createElement("div", { role: "current-id" },
|
|
91
|
+
"Current Task Id: ",
|
|
92
|
+
state.currentTaskId ?? '-'),
|
|
93
|
+
state.currentTaskId ? React.createElement(TaskDetails, { id: state.currentTaskId }) : React.createElement("div", null, "Click on a task to see details")));
|
|
94
|
+
};
|
|
95
|
+
const TasksList = ({ setTaskId }) => {
|
|
96
|
+
const allTodos = LiveStoreReact.useQuery(allTodos$);
|
|
97
|
+
return (React.createElement("div", null, allTodos.map((_) => (React.createElement("div", { key: _.id, onClick: () => setTaskId(_.id) }, _.id)))));
|
|
98
|
+
};
|
|
99
|
+
const TaskDetails = ({ id }) => {
|
|
100
|
+
const [todo] = LiveStoreReact.useRow(todos, id, { reactivityGraph });
|
|
101
|
+
return React.createElement("div", { role: "content" }, JSON.stringify(todo));
|
|
102
|
+
};
|
|
103
|
+
const renderResult = render(React.createElement(AppRouter, null), { wrapper });
|
|
104
|
+
expect(appRouterRenderCount.val).toBe(1);
|
|
105
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
106
|
+
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)`,
|
|
107
|
+
})));
|
|
108
|
+
expect(appRouterRenderCount.val).toBe(1);
|
|
109
|
+
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: -"');
|
|
110
|
+
React.act(() => globalSetState.currentTaskId('t1'));
|
|
111
|
+
expect(appRouterRenderCount.val).toBe(2);
|
|
112
|
+
expect(renderResult.getByRole('content').innerHTML).toMatchInlineSnapshot(`"{"id":"t1","text":"buy milk","completed":false}"`);
|
|
113
|
+
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t1"');
|
|
114
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
115
|
+
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t2', 'buy eggs', 0)`,
|
|
116
|
+
}), AppRouterSchema.update({ where: { id: 'singleton' }, values: { currentTaskId: 't2' } }), LiveStore.rawSqlMutation({
|
|
117
|
+
sql: LiveStore.sql `INSERT INTO todos (id, text, completed) VALUES ('t3', 'buy bread', 0)`,
|
|
118
|
+
})));
|
|
119
|
+
expect(appRouterRenderCount.val).toBe(3);
|
|
120
|
+
expect(renderResult.getByRole('current-id').innerHTML).toMatchInlineSnapshot('"Current Task Id: t2"');
|
|
121
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
122
|
+
it('should work for a useRow query chained with a useTemporary query', () => Effect.gen(function* () {
|
|
123
|
+
const { store, wrapper, reactivityGraph, makeRenderCount } = yield* makeTodoMvcReact({
|
|
124
|
+
useGlobalReactivityGraph: false,
|
|
125
|
+
});
|
|
126
|
+
const renderCount = makeRenderCount();
|
|
127
|
+
store.mutate(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy bread', completed: false }));
|
|
128
|
+
const { result, unmount, rerender } = renderHook((userId) => {
|
|
129
|
+
renderCount.inc();
|
|
130
|
+
const [_row, _setRow, rowState$] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph });
|
|
131
|
+
const todos = LiveStoreReact.useTemporaryQuery(() => LiveStore.querySQL((get) => LiveStore.sql `select * from todos where text like '%${get(rowState$).text}%'`, {
|
|
132
|
+
schema: Schema.Array(tables.todos.schema),
|
|
133
|
+
reactivityGraph,
|
|
134
|
+
label: 'todosFiltered',
|
|
135
|
+
}), userId);
|
|
136
|
+
return { todos };
|
|
137
|
+
}, { wrapper, initialProps: 'u1' });
|
|
138
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
139
|
+
sql: LiveStore.sql `INSERT INTO UserInfo (id, username, text) VALUES ('u2', 'username_u2', 'milk')`,
|
|
140
|
+
})));
|
|
141
|
+
expect(result.current.todos.length).toBe(2);
|
|
142
|
+
// expect(result.current.state.username).toBe('')
|
|
143
|
+
expect(renderCount.val).toBe(1);
|
|
144
|
+
rerender('u2');
|
|
145
|
+
expect(result.current.todos.length).toBe(1);
|
|
146
|
+
expect(renderCount.val).toBe(2);
|
|
147
|
+
unmount();
|
|
148
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
149
|
+
let cachedProvider;
|
|
150
|
+
describe('otel', () => {
|
|
151
|
+
const exporter = new InMemorySpanExporter();
|
|
152
|
+
const provider = cachedProvider ?? new BasicTracerProvider();
|
|
153
|
+
cachedProvider = provider;
|
|
154
|
+
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
|
|
155
|
+
provider.register();
|
|
156
|
+
const otelTracer = otel.trace.getTracer('test');
|
|
157
|
+
const span = otelTracer.startSpan('test');
|
|
158
|
+
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
159
|
+
it('should update the data based on component key', async () => {
|
|
160
|
+
const { strictMode } = await Effect.gen(function* () {
|
|
161
|
+
const { wrapper, store, reactivityGraph, makeRenderCount, strictMode } = yield* makeTodoMvcReact({
|
|
162
|
+
useGlobalReactivityGraph: false,
|
|
163
|
+
otelContext,
|
|
164
|
+
otelTracer,
|
|
165
|
+
});
|
|
166
|
+
const renderCount = makeRenderCount();
|
|
167
|
+
const { result, rerender, unmount } = renderHook((userId) => {
|
|
168
|
+
renderCount.inc();
|
|
169
|
+
const [state, setState] = LiveStoreReact.useRow(AppComponentSchema, userId, { reactivityGraph });
|
|
170
|
+
return { state, setState };
|
|
171
|
+
}, { wrapper, initialProps: 'u1' });
|
|
172
|
+
expect(result.current.state.id).toBe('u1');
|
|
173
|
+
expect(result.current.state.username).toBe('');
|
|
174
|
+
expect(renderCount.val).toBe(1);
|
|
175
|
+
React.act(() => store.mutate(LiveStore.rawSqlMutation({
|
|
176
|
+
sql: LiveStore.sql `INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')`,
|
|
177
|
+
})));
|
|
178
|
+
rerender('u2');
|
|
179
|
+
expect(result.current.state.id).toBe('u2');
|
|
180
|
+
expect(result.current.state.username).toBe('username_u2');
|
|
181
|
+
expect(renderCount.val).toBe(2);
|
|
182
|
+
unmount();
|
|
183
|
+
span.end();
|
|
184
|
+
return { strictMode };
|
|
185
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise);
|
|
186
|
+
const mapAttributes = (attributes) => {
|
|
187
|
+
return ReadonlyRecord.map(attributes, (val, key) => {
|
|
188
|
+
if (key === 'stackInfo') {
|
|
189
|
+
const stackInfo = JSON.parse(val);
|
|
190
|
+
// stackInfo.frames.shift() // Removes `renderHook.wrapper` from the stack
|
|
191
|
+
stackInfo.frames.forEach((_) => {
|
|
192
|
+
if (_.name.includes('renderHook.wrapper')) {
|
|
193
|
+
_.name = 'renderHook.wrapper';
|
|
194
|
+
}
|
|
195
|
+
_.filePath = '__REPLACED_FOR_SNAPSHOT__';
|
|
196
|
+
});
|
|
197
|
+
return JSON.stringify(stackInfo);
|
|
198
|
+
}
|
|
199
|
+
return val;
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
// TODO improve testing setup so "obsolete" warning is avoided
|
|
203
|
+
if (strictMode) {
|
|
204
|
+
expect(getSimplifiedRootSpan(exporter, mapAttributes)).toMatchSnapshot('strictMode=true');
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
expect(getSimplifiedRootSpan(exporter, mapAttributes)).toMatchSnapshot('strictMode=false');
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
//# sourceMappingURL=useRow.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRow.test.js","sourceRoot":"","sources":["../src/useRow.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAA;AACnF,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAC9G,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OA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AAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { QueryInfo } from '@livestore/common';
|
|
2
|
+
import type { LiveQuery } from '@livestore/livestore';
|
|
3
|
+
import * as otel from '@opentelemetry/api';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export type DepKey = string | number | ReadonlyArray<string | number>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
8
|
+
*
|
|
9
|
+
* The `key` is used to determine whether the a new query should be created or if the existing one should be reused.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useTemporaryQuery: <TResult>(makeQuery: () => LiveQuery<TResult>, key: DepKey) => TResult;
|
|
12
|
+
export declare const useTemporaryQueryRef: <TResult>(makeQuery: () => LiveQuery<TResult>, key: DepKey) => React.MutableRefObject<TResult>;
|
|
13
|
+
export declare const useMakeTemporaryQuery: <TResult, TQueryInfo extends QueryInfo>(makeQuery: (otelContext: otel.Context) => LiveQuery<TResult, TQueryInfo>, key: DepKey, options?: {
|
|
14
|
+
otel?: {
|
|
15
|
+
spanName?: string;
|
|
16
|
+
attributes?: otel.Attributes;
|
|
17
|
+
};
|
|
18
|
+
}) => {
|
|
19
|
+
query$: LiveQuery<TResult, TQueryInfo>;
|
|
20
|
+
otelContext: otel.Context;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useTemporaryQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemporaryQuery.d.ts","sourceRoot":"","sources":["../src/useTemporaryQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAuBzB,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;AAErE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,aAAa,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,MAAM,KAAG,OAChD,CAAA;AAE9C,eAAO,MAAM,oBAAoB,GAAI,OAAO,aAC/B,MAAM,SAAS,CAAC,OAAO,CAAC,OAC9B,MAAM,KACV,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAIhC,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,OAAO,EAAE,UAAU,SAAS,SAAS,aAC9D,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,OACnE,MAAM,YACD;IACR,IAAI,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,CAAA;KAC7B,CAAA;CACF,KACA;IAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAA;CA4ErE,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as otel from '@opentelemetry/api';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useStore } from './LiveStoreContext.js';
|
|
4
|
+
import { useQueryRef } from './useQuery.js';
|
|
5
|
+
// NOTE Given `useMemo` will be called multiple times (e.g. when using React Strict mode or Fast Refresh),
|
|
6
|
+
// we are using this cache to avoid starting multiple queries/spans for the same component.
|
|
7
|
+
// This is somewhat against some recommended React best practices, but it should be fine in our case below.
|
|
8
|
+
// Please definitely open an issue if you see or run into any problems with this approach!
|
|
9
|
+
const cache = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
12
|
+
*
|
|
13
|
+
* The `key` is used to determine whether the a new query should be created or if the existing one should be reused.
|
|
14
|
+
*/
|
|
15
|
+
export const useTemporaryQuery = (makeQuery, key) => useTemporaryQueryRef(makeQuery, key).current;
|
|
16
|
+
export const useTemporaryQueryRef = (makeQuery, key) => {
|
|
17
|
+
const { query$ } = useMakeTemporaryQuery(makeQuery, key);
|
|
18
|
+
return useQueryRef(query$);
|
|
19
|
+
};
|
|
20
|
+
export const useMakeTemporaryQuery = (makeQuery, key, options) => {
|
|
21
|
+
const { store } = useStore();
|
|
22
|
+
const fullKey = React.useMemo(
|
|
23
|
+
// NOTE We're using the `makeQuery` function body string to make sure the key is unique across the app
|
|
24
|
+
// TODO we should figure out whether this could cause some problems and/or if there's a better way to do this
|
|
25
|
+
() => (Array.isArray(key) ? key.join('-') : key) + '-' + store.reactivityGraph.id + '-' + makeQuery.toString(), [key, makeQuery, store.reactivityGraph.id]);
|
|
26
|
+
const fullKeyRef = React.useRef();
|
|
27
|
+
const { query$, otelContext } = React.useMemo(() => {
|
|
28
|
+
if (fullKeyRef.current !== undefined && fullKeyRef.current !== fullKey) {
|
|
29
|
+
// console.debug('fullKey changed', 'prev', fullKeyRef.current.split('-')[0]!, '-> new', fullKey.split('-')[0]!)
|
|
30
|
+
const cachedItem = cache.get(fullKeyRef.current);
|
|
31
|
+
if (cachedItem !== undefined && cachedItem._tag === 'active') {
|
|
32
|
+
cachedItem.rc--;
|
|
33
|
+
if (cachedItem.rc === 0) {
|
|
34
|
+
// console.debug('rc=0-changed', cachedItem.query$.id, cachedItem.query$.label)
|
|
35
|
+
cachedItem.query$.destroy();
|
|
36
|
+
cachedItem.span.end();
|
|
37
|
+
cache.set(fullKeyRef.current, { _tag: 'destroyed' });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const cachedItem = cache.get(fullKey);
|
|
42
|
+
if (cachedItem !== undefined && cachedItem._tag === 'active') {
|
|
43
|
+
// console.debug('rc++', cachedItem.query$.id, cachedItem.query$.label)
|
|
44
|
+
cachedItem.rc++;
|
|
45
|
+
return cachedItem;
|
|
46
|
+
}
|
|
47
|
+
const spanName = options?.otel?.spanName ?? `LiveStore:useTemporaryQuery:${key}`;
|
|
48
|
+
const span = store.otel.tracer.startSpan(spanName, { attributes: options?.otel?.attributes }, store.otel.queriesSpanContext);
|
|
49
|
+
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
50
|
+
const query$ = makeQuery(otelContext);
|
|
51
|
+
cache.set(fullKey, { _tag: 'active', rc: 1, query$, span, otelContext });
|
|
52
|
+
return { query$, otelContext };
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [fullKey]);
|
|
55
|
+
fullKeyRef.current = fullKey;
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
return () => {
|
|
58
|
+
const fullKey = fullKeyRef.current;
|
|
59
|
+
const cachedItem = cache.get(fullKey);
|
|
60
|
+
// NOTE in case the fullKey changed then the query was already destroyed in the useMemo above
|
|
61
|
+
if (cachedItem === undefined || cachedItem._tag === 'destroyed')
|
|
62
|
+
return;
|
|
63
|
+
// console.debug('rc--', cachedItem.query$.id, cachedItem.query$.label)
|
|
64
|
+
cachedItem.rc--;
|
|
65
|
+
if (cachedItem.rc === 0) {
|
|
66
|
+
// console.debug('rc=0', cachedItem.query$.id, cachedItem.query$.label)
|
|
67
|
+
cachedItem.query$.destroy();
|
|
68
|
+
cachedItem.span.end();
|
|
69
|
+
cache.delete(fullKey);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
return { query$, otelContext };
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=useTemporaryQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemporaryQuery.js","sourceRoot":"","sources":["../src/useTemporaryQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,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 +1,59 @@
|
|
|
1
|
+
import * as LiveStore from '@livestore/livestore';
|
|
2
|
+
import { querySQL } from '@livestore/livestore';
|
|
3
|
+
import { Effect, Schema } from '@livestore/utils/effect';
|
|
4
|
+
import { render, renderHook } from '@testing-library/react';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
// @ts-expect-error no types
|
|
7
|
+
import * as ReactWindow from 'react-window';
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { makeTodoMvcReact, tables, todos } from './__tests__/fixture.js';
|
|
10
|
+
import * as LiveStoreReact from './mod.js';
|
|
11
|
+
describe('useTemporaryQuery', () => {
|
|
12
|
+
it('simple', () => Effect.gen(function* () {
|
|
13
|
+
const { wrapper, store, makeRenderCount } = yield* makeTodoMvcReact();
|
|
14
|
+
const renderCount = makeRenderCount();
|
|
15
|
+
store.mutate(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy bread', completed: false }));
|
|
16
|
+
const queryMap = new Map();
|
|
17
|
+
const { rerender, result, unmount } = renderHook((id) => {
|
|
18
|
+
renderCount.inc();
|
|
19
|
+
return LiveStoreReact.useTemporaryQuery(() => {
|
|
20
|
+
const query$ = querySQL(`select * from todos where id = '${id}'`, {
|
|
21
|
+
schema: Schema.Array(tables.todos.schema),
|
|
22
|
+
});
|
|
23
|
+
queryMap.set(id, query$);
|
|
24
|
+
return query$;
|
|
25
|
+
}, id);
|
|
26
|
+
}, { wrapper, initialProps: 't1' });
|
|
27
|
+
expect(result.current.length).toBe(1);
|
|
28
|
+
expect(result.current[0].text).toBe('buy milk');
|
|
29
|
+
expect(renderCount.val).toBe(1);
|
|
30
|
+
expect(queryMap.get('t1').runs).toBe(1);
|
|
31
|
+
rerender('t2');
|
|
32
|
+
expect(result.current.length).toBe(1);
|
|
33
|
+
expect(result.current[0].text).toBe('buy bread');
|
|
34
|
+
expect(renderCount.val).toBe(2);
|
|
35
|
+
expect(queryMap.get('t1').runs).toBe(1);
|
|
36
|
+
expect(queryMap.get('t2').runs).toBe(1);
|
|
37
|
+
unmount();
|
|
38
|
+
expect(queryMap.get('t2').runs).toBe(1);
|
|
39
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
40
|
+
// NOTE this test covers some special react lifecyle paths which I couldn't easily reproduce without react-window
|
|
41
|
+
// it basically causes a "query swap" in the `useMemo` and both a `useEffect` cleanup call.
|
|
42
|
+
// To handle this properly we introduced the `_tag: 'destroyed'` state in the `spanAlreadyStartedCache`.
|
|
43
|
+
it('should work for a list with react-window', () => Effect.gen(function* () {
|
|
44
|
+
const { wrapper } = yield* makeTodoMvcReact();
|
|
45
|
+
const ListWrapper = ({ numItems }) => {
|
|
46
|
+
return (React.createElement(ReactWindow.FixedSizeList, { height: 100, width: 100, itemSize: 10, itemCount: numItems, itemData: Array.from({ length: numItems }, (_, i) => i).reverse() }, ListItem));
|
|
47
|
+
};
|
|
48
|
+
const ListItem = ({ data: ids, index }) => {
|
|
49
|
+
const id = ids[index];
|
|
50
|
+
const res = LiveStoreReact.useTemporaryQuery(() => LiveStore.computed(() => id, { label: `ListItem.${id}` }), id);
|
|
51
|
+
return React.createElement("div", { role: "listitem" }, res);
|
|
52
|
+
};
|
|
53
|
+
const renderResult = render(React.createElement(ListWrapper, { numItems: 1 }), { wrapper });
|
|
54
|
+
expect(renderResult.container.textContent).toBe('0');
|
|
55
|
+
renderResult.rerender(React.createElement(ListWrapper, { numItems: 2 }));
|
|
56
|
+
expect(renderResult.container.textContent).toBe('10');
|
|
57
|
+
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=useTemporaryQuery.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemporaryQuery.test.js","sourceRoot":"","sources":["../src/useTemporaryQuery.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;A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,CAAC,EAC/D,EAAE,CACH,CAAA;YACD,OAAO,6BAAK,IAAI,EAAC,UAAU,IAAE,GAAG,CAAO,CAAA;QACzC,CAAC,CAAA;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,oBAAC,WAAW,IAAC,QAAQ,EAAE,CAAC,GAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAEtE,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,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;AACxE,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-info.d.ts","sourceRoot":"","sources":["../../src/utils/stack-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAGrF,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAEvD,eAAO,MAAM,YAAY,QAAO,SAOxB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { extractStackInfoFromStackTrace } from '@livestore/livestore';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export const originalStackLimit = Error.stackTraceLimit;
|
|
4
|
+
export const useStackInfo = () => React.useMemo(() => {
|
|
5
|
+
Error.stackTraceLimit = 10;
|
|
6
|
+
// eslint-disable-next-line unicorn/error-message
|
|
7
|
+
const stack = new Error().stack;
|
|
8
|
+
Error.stackTraceLimit = originalStackLimit;
|
|
9
|
+
return extractStackInfoFromStackTrace(stack);
|
|
10
|
+
}, []);
|
|
11
|
+
//# sourceMappingURL=stack-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-info.js","sourceRoot":"","sources":["../../src/utils/stack-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAkB,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAEvD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE,CAC1C,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;IACjB,KAAK,CAAC,eAAe,GAAG,EAAE,CAAA;IAC1B,iDAAiD;IACjD,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAM,CAAA;IAChC,KAAK,CAAC,eAAe,GAAG,kBAAkB,CAAA;IAC1C,OAAO,8BAA8B,CAAC,KAAK,CAAC,CAAA;AAC9C,CAAC,EAAE,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A variant of `React.useState` which allows the `inputState` to change over time as well.
|
|
4
|
+
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
|
|
5
|
+
*
|
|
6
|
+
* Notes:
|
|
7
|
+
* - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
|
|
8
|
+
* - This hook might not work properly with React Suspense
|
|
9
|
+
* - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare const useStateRefWithReactiveInput: <T>(inputState: T) => [React.MutableRefObject<T>, (newState: T | ((prev: T) => T)) => void];
|
|
13
|
+
//# sourceMappingURL=useStateRefWithReactiveInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStateRefWithReactiveInput.d.ts","sourceRoot":"","sources":["../../src/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,cAChC,CAAC,KACZ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAwBtE,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A variant of `React.useState` which allows the `inputState` to change over time as well.
|
|
4
|
+
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
|
|
5
|
+
*
|
|
6
|
+
* Notes:
|
|
7
|
+
* - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
|
|
8
|
+
* - This hook might not work properly with React Suspense
|
|
9
|
+
* - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export const useStateRefWithReactiveInput = (inputState) => {
|
|
13
|
+
const [_, rerender] = React.useState(0);
|
|
14
|
+
const lastKnownInputStateRef = React.useRef(inputState);
|
|
15
|
+
const stateRef = React.useRef(inputState);
|
|
16
|
+
if (lastKnownInputStateRef.current !== inputState) {
|
|
17
|
+
lastKnownInputStateRef.current = inputState;
|
|
18
|
+
// NOTE we don't need to re-render here, because the component is already re-rendering due to the `inputState` change
|
|
19
|
+
stateRef.current = inputState;
|
|
20
|
+
}
|
|
21
|
+
const setStateAndRerender = React.useCallback((newState) => {
|
|
22
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/37663
|
|
23
|
+
const val = typeof newState === 'function' ? newState(stateRef.current) : newState;
|
|
24
|
+
stateRef.current = val;
|
|
25
|
+
rerender((c) => c + 1);
|
|
26
|
+
}, [rerender]);
|
|
27
|
+
return [stateRef, setStateAndRerender];
|
|
28
|
+
};
|
|
29
|
+
// Down-side of this implementation: Double render pass due to `setState` call (which forces a re-render)
|
|
30
|
+
// Keeping around for now in case `useStateRefWithReactiveInput` doesn't work out
|
|
31
|
+
// const _useStateWithReactiveInput = <T>(inputState: T): [T, (newState: T | ((prev: T) => T)) => void] => {
|
|
32
|
+
// const [externalState, setExternalState] = React.useState(inputState)
|
|
33
|
+
// if (externalState !== inputState) {
|
|
34
|
+
// setExternalState(inputState)
|
|
35
|
+
// }
|
|
36
|
+
// return [externalState, setExternalState]
|
|
37
|
+
// }
|
|
38
|
+
//# sourceMappingURL=useStateRefWithReactiveInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStateRefWithReactiveInput.js","sourceRoot":"","sources":["../../src/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAa,EAC0D,EAAE;IACzE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEvC,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAE5C,IAAI,sBAAsB,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAClD,sBAAsB,CAAC,OAAO,GAAG,UAAU,CAAA;QAE3C,qHAAqH;QACrH,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAA;IAC/B,CAAC;IAED,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAC3C,CAAC,QAA8B,EAAE,EAAE;QACjC,wEAAwE;QACxE,MAAM,GAAG,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QAClF,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAA;QACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAA;IAED,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;AACxC,CAAC,CAAA;AAED,yGAAyG;AACzG,iFAAiF;AACjF,4GAA4G;AAC5G,yEAAyE;AAEzE,wCAAwC;AACxC,mCAAmC;AACnC,MAAM;AAEN,6CAA6C;AAC7C,IAAI"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@livestore/react",
|
|
3
|
+
"version": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/mod.d.ts",
|
|
8
|
+
"default": "./dist/mod.js"
|
|
9
|
+
},
|
|
10
|
+
"./experimental": {
|
|
11
|
+
"types": "./dist/experimental/mod.d.ts",
|
|
12
|
+
"default": "./dist/experimental/mod.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "./dist/mod.d.ts",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"./experimental": [
|
|
19
|
+
"./dist/experimental/mod.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@opentelemetry/api": "^1.9.0",
|
|
25
|
+
"@livestore/common": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df",
|
|
26
|
+
"@livestore/utils": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df",
|
|
27
|
+
"@livestore/livestore": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df",
|
|
28
|
+
"@livestore/db-schema": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@opentelemetry/sdk-trace-base": "1.27.0",
|
|
32
|
+
"@testing-library/react": "^16.0.1",
|
|
33
|
+
"@types/react": "^18.3.12",
|
|
34
|
+
"@types/react-dom": "^18.3.1",
|
|
35
|
+
"jsdom": "^25.0.1",
|
|
36
|
+
"react": "^18.3.1",
|
|
37
|
+
"react-dom": "^18.3.1",
|
|
38
|
+
"react-window": "^1.8.10",
|
|
39
|
+
"typescript": "5.6.3",
|
|
40
|
+
"vite": "5.4.10",
|
|
41
|
+
"vitest": "^2.1.4",
|
|
42
|
+
"@livestore/web": "0.0.0-snapshot-8d3edf87cb1e88c7b67c5f3ea9d0b307253c33df"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^18"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc",
|
|
52
|
+
"test": "vitest && REACT_STRICT_MODE=1 vitest"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Store } from '@livestore/livestore'
|
|
2
|
+
import type { LiveStoreContextRunning as LiveStoreContext_ } from '@livestore/livestore/effect'
|
|
3
|
+
import React, { useContext } from 'react'
|
|
4
|
+
|
|
5
|
+
export const LiveStoreContext = React.createContext<LiveStoreContext_ | undefined>(undefined)
|
|
6
|
+
|
|
7
|
+
export const useStore = (): { store: Store } => {
|
|
8
|
+
const storeContext = useContext(LiveStoreContext)
|
|
9
|
+
|
|
10
|
+
if (storeContext === undefined) {
|
|
11
|
+
throw new Error(`useStore can only be used inside StoreContext.Provider`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (storeContext.stage !== 'running') {
|
|
15
|
+
throw new Error(`useStore can only be used after the store is running`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return storeContext
|
|
19
|
+
}
|