@livestore/react 0.3.0-dev.27 → 0.3.0-dev.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/LiveStoreContext.d.ts +10 -6
- package/dist/LiveStoreContext.d.ts.map +1 -1
- package/dist/LiveStoreContext.js +0 -14
- package/dist/LiveStoreContext.js.map +1 -1
- package/dist/LiveStoreProvider.d.ts +2 -2
- package/dist/LiveStoreProvider.d.ts.map +1 -1
- package/dist/LiveStoreProvider.js +5 -1
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +6 -5
- package/dist/LiveStoreProvider.test.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +115 -546
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +64 -22
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/mod.d.ts +4 -4
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -4
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts +61 -0
- package/dist/useClientDocument.d.ts.map +1 -0
- package/dist/useClientDocument.js +79 -0
- package/dist/useClientDocument.js.map +1 -0
- package/dist/useClientDocument.test.d.ts +2 -0
- package/dist/useClientDocument.test.d.ts.map +1 -0
- package/dist/{useRow.test.js → useClientDocument.test.js} +44 -48
- package/dist/useClientDocument.test.js.map +1 -0
- package/dist/useQuery.d.ts +1 -3
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +6 -3
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +16 -17
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useStore.d.ts +9 -0
- package/dist/useStore.d.ts.map +1 -0
- package/dist/useStore.js +28 -0
- package/dist/useStore.js.map +1 -0
- package/package.json +11 -11
- package/src/LiveStoreContext.ts +10 -19
- package/src/LiveStoreProvider.test.tsx +6 -5
- package/src/LiveStoreProvider.tsx +7 -4
- package/src/__snapshots__/{useRow.test.tsx.snap → useClientDocument.test.tsx.snap} +62 -46
- package/src/__snapshots__/useQuery.test.tsx.snap +8 -8
- package/src/__tests__/fixture.tsx +69 -39
- package/src/mod.ts +5 -5
- package/src/{useRow.test.tsx → useClientDocument.test.tsx} +51 -55
- package/src/useClientDocument.ts +157 -0
- package/src/useQuery.test.tsx +18 -19
- package/src/useQuery.ts +9 -8
- package/src/useStore.ts +36 -0
- package/tmp/pack.tgz +0 -0
- package/dist/useAtom.d.ts +0 -8
- package/dist/useAtom.d.ts.map +0 -1
- package/dist/useAtom.js +0 -42
- package/dist/useAtom.js.map +0 -1
- package/dist/useRow.d.ts +0 -64
- package/dist/useRow.d.ts.map +0 -1
- package/dist/useRow.js +0 -108
- package/dist/useRow.js.map +0 -1
- package/dist/useRow.test.d.ts +0 -2
- package/dist/useRow.test.d.ts.map +0 -1
- package/dist/useRow.test.js.map +0 -1
- package/src/useAtom.ts +0 -66
- package/src/useRow.ts +0 -210
|
@@ -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,25 @@ 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 value = json_set(value, ?, json(?))
|
|
45
|
+
",
|
|
42
46
|
},
|
|
43
47
|
},
|
|
44
48
|
],
|
|
@@ -49,9 +53,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
49
53
|
"_name": "LiveStore:queries",
|
|
50
54
|
"children": [
|
|
51
55
|
{
|
|
52
|
-
"_name": "LiveStore:
|
|
56
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u1",
|
|
53
57
|
"attributes": {
|
|
54
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
58
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
55
59
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
56
60
|
},
|
|
57
61
|
"children": [
|
|
@@ -66,17 +70,21 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
66
70
|
{
|
|
67
71
|
"_name": "LiveStore:commit",
|
|
68
72
|
"attributes": {
|
|
69
|
-
"livestore.commitLabel": "
|
|
70
|
-
"livestore.
|
|
71
|
-
"
|
|
73
|
+
"livestore.commitLabel": "UserInfo.set:u1",
|
|
74
|
+
"livestore.eventTags": [
|
|
75
|
+
"UserInfoSet",
|
|
72
76
|
],
|
|
73
|
-
"livestore.
|
|
77
|
+
"livestore.eventsCount": 1,
|
|
74
78
|
},
|
|
75
79
|
"children": [
|
|
76
80
|
{
|
|
77
81
|
"_name": "livestore.in-memory-db:execute",
|
|
78
82
|
"attributes": {
|
|
79
|
-
"sql.query": "
|
|
83
|
+
"sql.query": "
|
|
84
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
85
|
+
VALUES (?, ?)
|
|
86
|
+
ON CONFLICT (id) DO UPDATE SET value = json_set(json_set(value, ?, json(?)), ?, json(?))
|
|
87
|
+
",
|
|
80
88
|
},
|
|
81
89
|
},
|
|
82
90
|
],
|
|
@@ -84,7 +92,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
84
92
|
{
|
|
85
93
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
86
94
|
"attributes": {
|
|
87
|
-
"livestore.debugRefreshReason": "useQuery:initial-run:
|
|
95
|
+
"livestore.debugRefreshReason": "useQuery:initial-run:UserInfo.get:u1",
|
|
88
96
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
89
97
|
"sql.rowsCount": 1,
|
|
90
98
|
},
|
|
@@ -102,8 +110,8 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
102
110
|
{
|
|
103
111
|
"_name": "LiveStore.subscribe",
|
|
104
112
|
"attributes": {
|
|
105
|
-
"label": "
|
|
106
|
-
"queryLabel": "
|
|
113
|
+
"label": "UserInfo.get:u1",
|
|
114
|
+
"queryLabel": "UserInfo.get:u1",
|
|
107
115
|
},
|
|
108
116
|
"children": [
|
|
109
117
|
{
|
|
@@ -129,9 +137,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
129
137
|
],
|
|
130
138
|
},
|
|
131
139
|
{
|
|
132
|
-
"_name": "LiveStore:
|
|
140
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u2",
|
|
133
141
|
"attributes": {
|
|
134
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
142
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
135
143
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
136
144
|
},
|
|
137
145
|
"children": [
|
|
@@ -146,7 +154,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
146
154
|
{
|
|
147
155
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
148
156
|
"attributes": {
|
|
149
|
-
"livestore.debugRefreshReason": "useQuery:initial-run:
|
|
157
|
+
"livestore.debugRefreshReason": "useQuery:initial-run:UserInfo.get:u2",
|
|
150
158
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
151
159
|
"sql.rowsCount": 1,
|
|
152
160
|
},
|
|
@@ -164,14 +172,14 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
164
172
|
{
|
|
165
173
|
"_name": "LiveStore.subscribe",
|
|
166
174
|
"attributes": {
|
|
167
|
-
"label": "
|
|
168
|
-
"queryLabel": "
|
|
175
|
+
"label": "UserInfo.get:u2",
|
|
176
|
+
"queryLabel": "UserInfo.get:u2",
|
|
169
177
|
},
|
|
170
178
|
"children": [
|
|
171
179
|
{
|
|
172
180
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
173
181
|
"attributes": {
|
|
174
|
-
"livestore.debugRefreshReason": "subscribe-initial-run:
|
|
182
|
+
"livestore.debugRefreshReason": "subscribe-initial-run:UserInfo.get:u2",
|
|
175
183
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
176
184
|
"sql.rowsCount": 1,
|
|
177
185
|
},
|
|
@@ -196,7 +204,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
196
204
|
}
|
|
197
205
|
`;
|
|
198
206
|
|
|
199
|
-
exports[`
|
|
207
|
+
exports[`useClientDocument > otel > should update the data based on component key strictMode={ strictMode: true } 1`] = `
|
|
200
208
|
{
|
|
201
209
|
"_name": "createStore",
|
|
202
210
|
"attributes": {
|
|
@@ -220,21 +228,25 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
220
228
|
"_name": "LiveStore:sync",
|
|
221
229
|
},
|
|
222
230
|
{
|
|
223
|
-
"_name": "LiveStore:
|
|
231
|
+
"_name": "LiveStore:commits",
|
|
224
232
|
"children": [
|
|
225
233
|
{
|
|
226
234
|
"_name": "LiveStore:commit",
|
|
227
235
|
"attributes": {
|
|
228
|
-
"livestore.
|
|
229
|
-
"
|
|
236
|
+
"livestore.eventTags": [
|
|
237
|
+
"UserInfoSet",
|
|
230
238
|
],
|
|
231
|
-
"livestore.
|
|
239
|
+
"livestore.eventsCount": 1,
|
|
232
240
|
},
|
|
233
241
|
"children": [
|
|
234
242
|
{
|
|
235
243
|
"_name": "livestore.in-memory-db:execute",
|
|
236
244
|
"attributes": {
|
|
237
|
-
"sql.query": "
|
|
245
|
+
"sql.query": "
|
|
246
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
247
|
+
VALUES (?, ?)
|
|
248
|
+
ON CONFLICT (id) DO UPDATE SET value = json_set(value, ?, json(?))
|
|
249
|
+
",
|
|
238
250
|
},
|
|
239
251
|
},
|
|
240
252
|
],
|
|
@@ -245,9 +257,9 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
245
257
|
"_name": "LiveStore:queries",
|
|
246
258
|
"children": [
|
|
247
259
|
{
|
|
248
|
-
"_name": "LiveStore:
|
|
260
|
+
"_name": "LiveStore:useClientDocument:UserInfo:u1",
|
|
249
261
|
"attributes": {
|
|
250
|
-
"firstStackInfo": "{"frames":[{"name":"
|
|
262
|
+
"firstStackInfo": "{"frames":[{"name":"Store.store.useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useClientDocument","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
251
263
|
"label": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
252
264
|
},
|
|
253
265
|
"children": [
|
|
@@ -262,17 +274,21 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
262
274
|
{
|
|
263
275
|
"_name": "LiveStore:commit",
|
|
264
276
|
"attributes": {
|
|
265
|
-
"livestore.commitLabel": "
|
|
266
|
-
"livestore.
|
|
267
|
-
"
|
|
277
|
+
"livestore.commitLabel": "UserInfo.set:u1",
|
|
278
|
+
"livestore.eventTags": [
|
|
279
|
+
"UserInfoSet",
|
|
268
280
|
],
|
|
269
|
-
"livestore.
|
|
281
|
+
"livestore.eventsCount": 1,
|
|
270
282
|
},
|
|
271
283
|
"children": [
|
|
272
284
|
{
|
|
273
285
|
"_name": "livestore.in-memory-db:execute",
|
|
274
286
|
"attributes": {
|
|
275
|
-
"sql.query": "
|
|
287
|
+
"sql.query": "
|
|
288
|
+
INSERT INTO 'UserInfo' (id, value)
|
|
289
|
+
VALUES (?, ?)
|
|
290
|
+
ON CONFLICT (id) DO UPDATE SET value = json_set(json_set(value, ?, json(?)), ?, json(?))
|
|
291
|
+
",
|
|
276
292
|
},
|
|
277
293
|
},
|
|
278
294
|
],
|
|
@@ -280,7 +296,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
280
296
|
{
|
|
281
297
|
"_name": "db:SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
282
298
|
"attributes": {
|
|
283
|
-
"livestore.debugRefreshReason": "useQuery:initial-run:
|
|
299
|
+
"livestore.debugRefreshReason": "useQuery:initial-run:UserInfo.get:u1",
|
|
284
300
|
"sql.query": "SELECT * FROM 'UserInfo' WHERE id = ?",
|
|
285
301
|
"sql.rowsCount": 1,
|
|
286
302
|
},
|
|
@@ -298,8 +314,8 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
298
314
|
{
|
|
299
315
|
"_name": "LiveStore.subscribe",
|
|
300
316
|
"attributes": {
|
|
301
|
-
"label": "
|
|
302
|
-
"queryLabel": "
|
|
317
|
+
"label": "UserInfo.get:u1",
|
|
318
|
+
"queryLabel": "UserInfo.get:u1",
|
|
303
319
|
},
|
|
304
320
|
"children": [
|
|
305
321
|
{
|
|
@@ -330,7 +346,7 @@ exports[`useRow > otel > should update the data based on component key strictMod
|
|
|
330
346
|
}
|
|
331
347
|
`;
|
|
332
348
|
|
|
333
|
-
exports[`
|
|
349
|
+
exports[`useClientDocument > should update the data based on component key 1`] = `
|
|
334
350
|
{
|
|
335
351
|
"atoms": [
|
|
336
352
|
{
|
|
@@ -408,13 +424,13 @@ exports[`useRow > should update the data based on component key 1`] = `
|
|
|
408
424
|
"id": "node-5",
|
|
409
425
|
"isDestroyed": false,
|
|
410
426
|
"isDirty": false,
|
|
411
|
-
"label": "
|
|
427
|
+
"label": "UserInfo.get:u1:results",
|
|
412
428
|
"meta": {
|
|
413
429
|
"liveStoreThunkType": "db.result",
|
|
414
430
|
},
|
|
415
431
|
"previousResult": {
|
|
416
432
|
"_tag": "Some",
|
|
417
|
-
"value": "{"username":"","text":""
|
|
433
|
+
"value": "{"username":"","text":""}",
|
|
418
434
|
},
|
|
419
435
|
"recomputations": 1,
|
|
420
436
|
"sub": [
|
|
@@ -432,7 +448,7 @@ exports[`useRow > should update the data based on component key 1`] = `
|
|
|
432
448
|
"id": "node-6",
|
|
433
449
|
"invocations": 1,
|
|
434
450
|
"isDestroyed": false,
|
|
435
|
-
"label": "subscribe:
|
|
451
|
+
"label": "subscribe:UserInfo.get:u1",
|
|
436
452
|
"sub": [
|
|
437
453
|
"node-5",
|
|
438
454
|
],
|
|
@@ -441,7 +457,7 @@ exports[`useRow > should update the data based on component key 1`] = `
|
|
|
441
457
|
}
|
|
442
458
|
`;
|
|
443
459
|
|
|
444
|
-
exports[`
|
|
460
|
+
exports[`useClientDocument > should update the data based on component key 2`] = `
|
|
445
461
|
{
|
|
446
462
|
"atoms": [
|
|
447
463
|
{
|
|
@@ -519,13 +535,13 @@ exports[`useRow > should update the data based on component key 2`] = `
|
|
|
519
535
|
"id": "node-7",
|
|
520
536
|
"isDestroyed": false,
|
|
521
537
|
"isDirty": false,
|
|
522
|
-
"label": "
|
|
538
|
+
"label": "UserInfo.get:u2:results",
|
|
523
539
|
"meta": {
|
|
524
540
|
"liveStoreThunkType": "db.result",
|
|
525
541
|
},
|
|
526
542
|
"previousResult": {
|
|
527
543
|
"_tag": "Some",
|
|
528
|
-
"value": "{"username":"username_u2","text":""
|
|
544
|
+
"value": "{"username":"username_u2","text":""}",
|
|
529
545
|
},
|
|
530
546
|
"recomputations": 2,
|
|
531
547
|
"sub": [
|
|
@@ -543,7 +559,7 @@ exports[`useRow > should update the data based on component key 2`] = `
|
|
|
543
559
|
"id": "node-8",
|
|
544
560
|
"invocations": 1,
|
|
545
561
|
"isDestroyed": false,
|
|
546
|
-
"label": "subscribe:
|
|
562
|
+
"label": "subscribe:UserInfo.get:u2",
|
|
547
563
|
"sub": [
|
|
548
564
|
"node-7",
|
|
549
565
|
],
|
|
@@ -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
|
{
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
2
2
|
import { provideOtel } from '@livestore/common'
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import { Events, makeSchema, State } from '@livestore/common/schema'
|
|
4
|
+
import type { Store } from '@livestore/livestore'
|
|
5
5
|
import { createStore } from '@livestore/livestore'
|
|
6
|
-
import { Effect } from '@livestore/utils/effect'
|
|
6
|
+
import { Effect, Schema } from '@livestore/utils/effect'
|
|
7
7
|
import type * as otel from '@opentelemetry/api'
|
|
8
8
|
import React from 'react'
|
|
9
9
|
|
|
@@ -22,45 +22,70 @@ export type AppState = {
|
|
|
22
22
|
filter: Filter
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
'todos',
|
|
27
|
-
{
|
|
28
|
-
id:
|
|
29
|
-
text:
|
|
30
|
-
completed:
|
|
25
|
+
const todos = State.SQLite.table({
|
|
26
|
+
name: 'todos',
|
|
27
|
+
columns: {
|
|
28
|
+
id: State.SQLite.text({ primaryKey: true }),
|
|
29
|
+
text: State.SQLite.text({ default: '', nullable: false }),
|
|
30
|
+
completed: State.SQLite.boolean({ default: false, nullable: false }),
|
|
31
31
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
filter: DbSchema.text({ default: 'all', nullable: false }),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const app = State.SQLite.table({
|
|
35
|
+
name: 'app',
|
|
36
|
+
columns: {
|
|
37
|
+
id: State.SQLite.text({ primaryKey: true, default: 'static' }),
|
|
38
|
+
newTodoText: State.SQLite.text({ default: '', nullable: true }),
|
|
39
|
+
filter: State.SQLite.text({ default: 'all', nullable: false }),
|
|
41
40
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const userInfo = State.SQLite.clientDocument({
|
|
44
|
+
name: 'UserInfo',
|
|
45
|
+
schema: Schema.Struct({
|
|
46
|
+
username: Schema.String,
|
|
47
|
+
text: Schema.String,
|
|
48
|
+
}),
|
|
49
|
+
default: { value: { username: '', text: '' } },
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const AppRouterSchema = State.SQLite.clientDocument({
|
|
53
|
+
name: 'AppRouter',
|
|
54
|
+
schema: Schema.Struct({
|
|
55
|
+
currentTaskId: Schema.String.pipe(Schema.NullOr),
|
|
56
|
+
}),
|
|
57
|
+
default: {
|
|
58
|
+
value: { currentTaskId: null },
|
|
59
|
+
id: 'singleton',
|
|
50
60
|
},
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
export const events = {
|
|
64
|
+
todoCreated: Events.synced({
|
|
65
|
+
name: 'todoCreated',
|
|
66
|
+
schema: Schema.Struct({ id: Schema.String, text: Schema.String, completed: Schema.Boolean }),
|
|
67
|
+
}),
|
|
68
|
+
todoUpdated: Events.synced({
|
|
69
|
+
name: 'todoUpdated',
|
|
70
|
+
schema: Schema.Struct({
|
|
71
|
+
id: Schema.String,
|
|
72
|
+
text: Schema.String.pipe(Schema.optional),
|
|
73
|
+
completed: Schema.Boolean.pipe(Schema.optional),
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
AppRouterSet: AppRouterSchema.set,
|
|
77
|
+
UserInfoSet: userInfo.set,
|
|
78
|
+
}
|
|
53
79
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
{ isSingleton: true, deriveMutations: { clientOnly: true } },
|
|
60
|
-
)
|
|
80
|
+
const materializers = State.SQLite.materializers(events, {
|
|
81
|
+
todoCreated: ({ id, text, completed }) => todos.insert({ id, text, completed }),
|
|
82
|
+
todoUpdated: ({ id, text, completed }) => todos.update({ completed, text }).where({ id }),
|
|
83
|
+
})
|
|
61
84
|
|
|
62
85
|
export const tables = { todos, app, userInfo, AppRouterSchema }
|
|
63
|
-
|
|
86
|
+
|
|
87
|
+
const state = State.SQLite.makeState({ tables, materializers })
|
|
88
|
+
export const schema = makeSchema({ state, events })
|
|
64
89
|
|
|
65
90
|
export const makeTodoMvcReact = ({
|
|
66
91
|
otelTracer,
|
|
@@ -87,15 +112,20 @@ export const makeTodoMvcReact = ({
|
|
|
87
112
|
}
|
|
88
113
|
}
|
|
89
114
|
|
|
90
|
-
const store = yield* createStore({
|
|
115
|
+
const store: Store<any> = yield* createStore({
|
|
91
116
|
schema,
|
|
92
117
|
storeId: 'default',
|
|
93
118
|
adapter: makeInMemoryAdapter(),
|
|
94
119
|
debug: { instanceId: 'test' },
|
|
95
120
|
})
|
|
96
121
|
|
|
122
|
+
const storeWithReactApi = LiveStoreReact.withReactApi(store)
|
|
123
|
+
|
|
97
124
|
// TODO improve typing of `LiveStoreContext`
|
|
98
|
-
const storeContext = {
|
|
125
|
+
const storeContext = {
|
|
126
|
+
stage: 'running' as const,
|
|
127
|
+
store: storeWithReactApi,
|
|
128
|
+
}
|
|
99
129
|
|
|
100
130
|
const MaybeStrictMode = strictMode ? React.StrictMode : React.Fragment
|
|
101
131
|
|
|
@@ -109,5 +139,5 @@ export const makeTodoMvcReact = ({
|
|
|
109
139
|
|
|
110
140
|
const renderCount = makeRenderCount()
|
|
111
141
|
|
|
112
|
-
return { wrapper, store, renderCount }
|
|
142
|
+
return { wrapper, store: storeWithReactApi, renderCount }
|
|
113
143
|
}).pipe(provideOtel({ parentSpanContext: otelContext, otelTracer }))
|
package/src/mod.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { LiveStoreContext,
|
|
1
|
+
export { LiveStoreContext, type ReactApi } from './LiveStoreContext.js'
|
|
2
|
+
export { useStore, withReactApi } from './useStore.js'
|
|
2
3
|
export { LiveStoreProvider } from './LiveStoreProvider.js'
|
|
3
|
-
export { useQuery } from './useQuery.js'
|
|
4
4
|
export { useStackInfo } from './utils/stack-info.js'
|
|
5
|
+
export { useQuery, useQueryRef } from './useQuery.js'
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
+
useClientDocument,
|
|
7
8
|
type StateSetters,
|
|
8
9
|
type SetStateAction,
|
|
9
10
|
type Dispatch,
|
|
10
11
|
type UseRowResult as UseStateResult,
|
|
11
|
-
} from './
|
|
12
|
-
export { useAtom } from './useAtom.js'
|
|
12
|
+
} from './useClientDocument.js'
|