@livestore/react 0.4.0-dev.22 → 0.4.0-dev.23
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 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/StoreRegistryContext.d.ts +1 -1
- package/dist/StoreRegistryContext.d.ts.map +1 -1
- package/dist/StoreRegistryContext.js +2 -2
- package/dist/StoreRegistryContext.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +8 -280
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +8 -78
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.d.ts.map +1 -1
- package/dist/experimental/components/LiveList.js +5 -4
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/mod.d.ts +4 -2
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +3 -2
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts +1 -26
- package/dist/useClientDocument.d.ts.map +1 -1
- package/dist/useClientDocument.js +2 -13
- package/dist/useClientDocument.js.map +1 -1
- package/dist/useClientDocument.test.js +12 -4
- package/dist/useClientDocument.test.js.map +1 -1
- package/dist/useQuery.d.ts +3 -4
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +10 -80
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +7 -8
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useRcResource.d.ts.map +1 -1
- package/dist/useRcResource.js +9 -5
- package/dist/useRcResource.js.map +1 -1
- package/dist/useRcResource.test.js +1 -1
- package/dist/useRcResource.test.js.map +1 -1
- package/dist/useStore.d.ts +12 -1
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +21 -13
- package/dist/useStore.js.map +1 -1
- package/dist/useStore.test.js +53 -8
- package/dist/useStore.test.js.map +1 -1
- package/dist/useSyncStatus.d.ts +22 -0
- package/dist/useSyncStatus.d.ts.map +1 -0
- package/dist/useSyncStatus.js +28 -0
- package/dist/useSyncStatus.js.map +1 -0
- package/package.json +68 -25
- package/src/StoreRegistryContext.tsx +4 -3
- package/src/__snapshots__/useClientDocument.test.tsx.snap +112 -78
- package/src/__tests__/fixture.tsx +22 -105
- package/src/experimental/components/LiveList.tsx +9 -5
- package/src/mod.ts +4 -9
- package/src/useClientDocument.test.tsx +16 -6
- package/src/useClientDocument.ts +6 -56
- package/src/useQuery.test.tsx +8 -8
- package/src/useQuery.ts +28 -113
- package/src/useRcResource.test.tsx +1 -1
- package/src/useRcResource.ts +10 -5
- package/src/useStore.test.tsx +85 -9
- package/src/useStore.ts +30 -17
- package/src/useSyncStatus.ts +34 -0
- package/dist/utils/stack-info.d.ts +0 -4
- package/dist/utils/stack-info.d.ts.map +0 -1
- package/dist/utils/stack-info.js +0 -10
- package/dist/utils/stack-info.js.map +0 -1
- package/src/ambient.d.ts +0 -1
- package/src/utils/stack-info.ts +0 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StoreRegistry } from '@livestore/livestore';
|
|
2
1
|
import * as React from 'react';
|
|
2
|
+
import type { StoreRegistry } from '@livestore/livestore';
|
|
3
3
|
export declare const StoreRegistryContext: React.Context<StoreRegistry | undefined>;
|
|
4
4
|
export type StoreRegistryProviderProps = {
|
|
5
5
|
storeRegistry: StoreRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistryContext.d.ts","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"StoreRegistryContext.d.ts","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,eAAO,MAAM,oBAAoB,0CAA4D,CAAA;AAE7F,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,qBAAqB,GAAI,6BAA6B,0BAA0B,KAAG,KAAK,CAAC,GAAG,CAAC,OAEzG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,aAAa,kBAQxD,CAAA"}
|
|
@@ -51,10 +51,10 @@ export const StoreRegistryProvider = ({ storeRegistry, children }) => {
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export const useStoreRegistry = (override) => {
|
|
54
|
-
if (override)
|
|
54
|
+
if (override !== undefined)
|
|
55
55
|
return override;
|
|
56
56
|
const storeRegistry = React.use(StoreRegistryContext);
|
|
57
|
-
if (
|
|
57
|
+
if (storeRegistry == null)
|
|
58
58
|
throw new Error('useStoreRegistry() must be used within <StoreRegistryProvider>');
|
|
59
59
|
return storeRegistry;
|
|
60
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistryContext.js","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"StoreRegistryContext.js","sourceRoot":"","sources":["../src/StoreRegistryContext.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAA4B,SAAS,CAAC,CAAA;AAO7F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,aAAa,EAAE,QAAQ,EAA8B,EAAqB,EAAE;IAClH,OAAO,KAAC,oBAAoB,IAAC,KAAK,EAAE,aAAa,YAAG,QAAQ,GAAwB,CAAA;AACtF,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAwB,EAAE,EAAE;IAC3D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAA;IAE3C,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAErD,IAAI,aAAa,IAAI,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;IAE5G,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
|
|
@@ -1,289 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import { Effect,
|
|
5
|
-
import type * as otel from '@opentelemetry/api';
|
|
1
|
+
import type { UnknownError } from '@livestore/common';
|
|
2
|
+
import { type AppState, type CreateTodoMvcStoreOptions, events, type Filter, schema, type Todo, tables } from '@livestore/framework-toolkit/testing';
|
|
3
|
+
import type { Store } from '@livestore/livestore';
|
|
4
|
+
import { Effect, type Scope } from '@livestore/utils/effect';
|
|
6
5
|
import React from 'react';
|
|
7
6
|
import * as LiveStoreReact from '../mod.ts';
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
completed: boolean;
|
|
12
|
-
};
|
|
13
|
-
export type Filter = 'all' | 'active' | 'completed';
|
|
14
|
-
export type AppState = {
|
|
15
|
-
newTodoText: string;
|
|
16
|
-
filter: Filter;
|
|
17
|
-
};
|
|
18
|
-
export declare const events: {
|
|
19
|
-
todoCreated: State.SQLite.EventDef<"todoCreated", {
|
|
20
|
-
readonly id: string;
|
|
21
|
-
readonly text: string;
|
|
22
|
-
readonly completed: boolean;
|
|
23
|
-
}, {
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly text: string;
|
|
26
|
-
readonly completed: boolean;
|
|
27
|
-
}>;
|
|
28
|
-
todoUpdated: State.SQLite.EventDef<"todoUpdated", {
|
|
29
|
-
readonly id: string;
|
|
30
|
-
readonly text?: string | undefined;
|
|
31
|
-
readonly completed?: boolean | undefined;
|
|
32
|
-
}, {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly text?: string | undefined;
|
|
35
|
-
readonly completed?: boolean | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
AppRouterSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"AppRouter", {
|
|
38
|
-
readonly currentTaskId: string | null;
|
|
39
|
-
}, {
|
|
40
|
-
partialSet: true;
|
|
41
|
-
default: {
|
|
42
|
-
id: "singleton";
|
|
43
|
-
value: {
|
|
44
|
-
readonly currentTaskId: null;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
}>;
|
|
48
|
-
UserInfoSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"UserInfo", {
|
|
49
|
-
readonly text: string;
|
|
50
|
-
readonly username: string;
|
|
51
|
-
}, {
|
|
52
|
-
partialSet: true;
|
|
53
|
-
default: {
|
|
54
|
-
id: undefined;
|
|
55
|
-
value: {
|
|
56
|
-
readonly username: "";
|
|
57
|
-
readonly text: "";
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
}>;
|
|
61
|
-
KvSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"Kv", any, {
|
|
62
|
-
partialSet: false;
|
|
63
|
-
default: {
|
|
64
|
-
id: undefined;
|
|
65
|
-
value: null;
|
|
66
|
-
};
|
|
67
|
-
}>;
|
|
68
|
-
};
|
|
69
|
-
export declare const tables: {
|
|
70
|
-
todos: State.SQLite.TableDef<State.SQLite.SqliteTableDefForInput<"todos", {
|
|
71
|
-
readonly id: {
|
|
72
|
-
columnType: "text";
|
|
73
|
-
schema: Schema.Schema<string, string, never>;
|
|
74
|
-
default: import("effect/Option").None<never>;
|
|
75
|
-
nullable: false;
|
|
76
|
-
primaryKey: true;
|
|
77
|
-
autoIncrement: false;
|
|
78
|
-
};
|
|
79
|
-
readonly text: {
|
|
80
|
-
columnType: "text";
|
|
81
|
-
schema: Schema.Schema<string, string, never>;
|
|
82
|
-
default: import("effect/Option").Some<"">;
|
|
83
|
-
nullable: false;
|
|
84
|
-
primaryKey: false;
|
|
85
|
-
autoIncrement: false;
|
|
86
|
-
};
|
|
87
|
-
readonly completed: {
|
|
88
|
-
columnType: "integer";
|
|
89
|
-
schema: Schema.Schema<boolean, number, never>;
|
|
90
|
-
default: import("effect/Option").Some<false>;
|
|
91
|
-
nullable: false;
|
|
92
|
-
primaryKey: false;
|
|
93
|
-
autoIncrement: false;
|
|
94
|
-
};
|
|
95
|
-
}>, State.SQLite.WithDefaults<{
|
|
96
|
-
readonly id: {
|
|
97
|
-
columnType: "text";
|
|
98
|
-
schema: Schema.Schema<string, string, never>;
|
|
99
|
-
default: import("effect/Option").None<never>;
|
|
100
|
-
nullable: false;
|
|
101
|
-
primaryKey: true;
|
|
102
|
-
autoIncrement: false;
|
|
103
|
-
};
|
|
104
|
-
readonly text: {
|
|
105
|
-
columnType: "text";
|
|
106
|
-
schema: Schema.Schema<string, string, never>;
|
|
107
|
-
default: import("effect/Option").Some<"">;
|
|
108
|
-
nullable: false;
|
|
109
|
-
primaryKey: false;
|
|
110
|
-
autoIncrement: false;
|
|
111
|
-
};
|
|
112
|
-
readonly completed: {
|
|
113
|
-
columnType: "integer";
|
|
114
|
-
schema: Schema.Schema<boolean, number, never>;
|
|
115
|
-
default: import("effect/Option").Some<false>;
|
|
116
|
-
nullable: false;
|
|
117
|
-
primaryKey: false;
|
|
118
|
-
autoIncrement: false;
|
|
119
|
-
};
|
|
120
|
-
}>, Schema.Schema<{
|
|
121
|
-
readonly id: string;
|
|
122
|
-
readonly text: string;
|
|
123
|
-
readonly completed: boolean;
|
|
124
|
-
}, {
|
|
125
|
-
readonly id: string;
|
|
126
|
-
readonly text: string;
|
|
127
|
-
readonly completed: number;
|
|
128
|
-
}, never>>;
|
|
129
|
-
app: State.SQLite.TableDef<State.SQLite.SqliteTableDefForInput<"app", {
|
|
130
|
-
readonly id: {
|
|
131
|
-
columnType: "text";
|
|
132
|
-
schema: Schema.Schema<string, string, never>;
|
|
133
|
-
default: import("effect/Option").Some<"static">;
|
|
134
|
-
nullable: false;
|
|
135
|
-
primaryKey: true;
|
|
136
|
-
autoIncrement: false;
|
|
137
|
-
};
|
|
138
|
-
readonly newTodoText: {
|
|
139
|
-
columnType: "text";
|
|
140
|
-
schema: Schema.Schema<string | null, string | null, never>;
|
|
141
|
-
default: import("effect/Option").Some<"">;
|
|
142
|
-
nullable: true;
|
|
143
|
-
primaryKey: false;
|
|
144
|
-
autoIncrement: false;
|
|
145
|
-
};
|
|
146
|
-
readonly filter: {
|
|
147
|
-
columnType: "text";
|
|
148
|
-
schema: Schema.Schema<string, string, never>;
|
|
149
|
-
default: import("effect/Option").Some<"all">;
|
|
150
|
-
nullable: false;
|
|
151
|
-
primaryKey: false;
|
|
152
|
-
autoIncrement: false;
|
|
153
|
-
};
|
|
154
|
-
}>, State.SQLite.WithDefaults<{
|
|
155
|
-
readonly id: {
|
|
156
|
-
columnType: "text";
|
|
157
|
-
schema: Schema.Schema<string, string, never>;
|
|
158
|
-
default: import("effect/Option").Some<"static">;
|
|
159
|
-
nullable: false;
|
|
160
|
-
primaryKey: true;
|
|
161
|
-
autoIncrement: false;
|
|
162
|
-
};
|
|
163
|
-
readonly newTodoText: {
|
|
164
|
-
columnType: "text";
|
|
165
|
-
schema: Schema.Schema<string | null, string | null, never>;
|
|
166
|
-
default: import("effect/Option").Some<"">;
|
|
167
|
-
nullable: true;
|
|
168
|
-
primaryKey: false;
|
|
169
|
-
autoIncrement: false;
|
|
170
|
-
};
|
|
171
|
-
readonly filter: {
|
|
172
|
-
columnType: "text";
|
|
173
|
-
schema: Schema.Schema<string, string, never>;
|
|
174
|
-
default: import("effect/Option").Some<"all">;
|
|
175
|
-
nullable: false;
|
|
176
|
-
primaryKey: false;
|
|
177
|
-
autoIncrement: false;
|
|
178
|
-
};
|
|
179
|
-
}>, Schema.Schema<{
|
|
180
|
-
readonly id: string;
|
|
181
|
-
readonly newTodoText: string | null;
|
|
182
|
-
readonly filter: string;
|
|
183
|
-
}, {
|
|
184
|
-
readonly id: string;
|
|
185
|
-
readonly newTodoText: string | null;
|
|
186
|
-
readonly filter: string;
|
|
187
|
-
}, never>>;
|
|
188
|
-
userInfo: State.SQLite.ClientDocumentTableDef<"UserInfo", {
|
|
189
|
-
readonly text: string;
|
|
190
|
-
readonly username: string;
|
|
191
|
-
}, {
|
|
192
|
-
readonly text: string;
|
|
193
|
-
readonly username: string;
|
|
194
|
-
}, {
|
|
195
|
-
partialSet: true;
|
|
196
|
-
default: {
|
|
197
|
-
id: undefined;
|
|
198
|
-
value: {
|
|
199
|
-
readonly username: "";
|
|
200
|
-
readonly text: "";
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
}>;
|
|
204
|
-
AppRouterSchema: State.SQLite.ClientDocumentTableDef<"AppRouter", {
|
|
205
|
-
readonly currentTaskId: string | null;
|
|
206
|
-
}, {
|
|
207
|
-
readonly currentTaskId: string | null;
|
|
208
|
-
}, {
|
|
209
|
-
partialSet: true;
|
|
210
|
-
default: {
|
|
211
|
-
id: "singleton";
|
|
212
|
-
value: {
|
|
213
|
-
readonly currentTaskId: null;
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
}>;
|
|
217
|
-
kv: State.SQLite.ClientDocumentTableDef<"Kv", any, any, {
|
|
218
|
-
partialSet: false;
|
|
219
|
-
default: {
|
|
220
|
-
id: undefined;
|
|
221
|
-
value: null;
|
|
222
|
-
};
|
|
223
|
-
}>;
|
|
224
|
-
};
|
|
225
|
-
export declare const schema: import("@livestore/livestore").FromInputSchema.DeriveSchema<{
|
|
226
|
-
state: import("@livestore/livestore").InternalState;
|
|
227
|
-
events: {
|
|
228
|
-
todoCreated: State.SQLite.EventDef<"todoCreated", {
|
|
229
|
-
readonly id: string;
|
|
230
|
-
readonly text: string;
|
|
231
|
-
readonly completed: boolean;
|
|
232
|
-
}, {
|
|
233
|
-
readonly id: string;
|
|
234
|
-
readonly text: string;
|
|
235
|
-
readonly completed: boolean;
|
|
236
|
-
}>;
|
|
237
|
-
todoUpdated: State.SQLite.EventDef<"todoUpdated", {
|
|
238
|
-
readonly id: string;
|
|
239
|
-
readonly text?: string | undefined;
|
|
240
|
-
readonly completed?: boolean | undefined;
|
|
241
|
-
}, {
|
|
242
|
-
readonly id: string;
|
|
243
|
-
readonly text?: string | undefined;
|
|
244
|
-
readonly completed?: boolean | undefined;
|
|
245
|
-
}>;
|
|
246
|
-
AppRouterSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"AppRouter", {
|
|
247
|
-
readonly currentTaskId: string | null;
|
|
248
|
-
}, {
|
|
249
|
-
partialSet: true;
|
|
250
|
-
default: {
|
|
251
|
-
id: "singleton";
|
|
252
|
-
value: {
|
|
253
|
-
readonly currentTaskId: null;
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
}>;
|
|
257
|
-
UserInfoSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"UserInfo", {
|
|
258
|
-
readonly text: string;
|
|
259
|
-
readonly username: string;
|
|
260
|
-
}, {
|
|
261
|
-
partialSet: true;
|
|
262
|
-
default: {
|
|
263
|
-
id: undefined;
|
|
264
|
-
value: {
|
|
265
|
-
readonly username: "";
|
|
266
|
-
readonly text: "";
|
|
267
|
-
};
|
|
268
|
-
};
|
|
269
|
-
}>;
|
|
270
|
-
KvSet: State.SQLite.ClientDocumentTableDef.SetEventDefLike<"Kv", any, {
|
|
271
|
-
partialSet: false;
|
|
272
|
-
default: {
|
|
273
|
-
id: undefined;
|
|
274
|
-
value: null;
|
|
275
|
-
};
|
|
276
|
-
}>;
|
|
277
|
-
};
|
|
278
|
-
}>;
|
|
279
|
-
export type MakeTodoMvcReactOptions = {
|
|
280
|
-
otelTracer?: otel.Tracer | undefined;
|
|
281
|
-
otelContext?: otel.Context | undefined;
|
|
7
|
+
export { events, schema, tables };
|
|
8
|
+
export type { AppState, Filter, Todo };
|
|
9
|
+
export type MakeTodoMvcReactOptions = CreateTodoMvcStoreOptions & {
|
|
282
10
|
strictMode?: boolean | undefined;
|
|
283
11
|
};
|
|
284
12
|
export declare const makeTodoMvcReact: (opts?: MakeTodoMvcReactOptions) => Effect.Effect<{
|
|
285
13
|
wrapper: ({ children }: any) => React.JSX.Element;
|
|
286
|
-
store: Store<
|
|
14
|
+
store: Store<typeof schema> & LiveStoreReact.ReactApi;
|
|
287
15
|
renderCount: {
|
|
288
16
|
readonly val: number;
|
|
289
17
|
inc: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,yBAAyB,EAE9B,MAAM,EACN,KAAK,MAAM,EACX,MAAM,EACN,KAAK,IAAI,EACT,MAAM,EACP,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,cAAc,MAAM,WAAW,CAAA;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACjC,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;AAEtC,MAAM,MAAM,uBAAuB,GAAG,yBAAyB,GAAG;IAChE,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,uBAAuB,KAAK,MAAM,CAAC,MAAM,CAC9E;IACE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;IACjD,KAAK,EAAE,KAAK,CAAC,OAAO,MAAM,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAA;IACrD,WAAW,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CACvD,EACD,YAAY,EACZ,KAAK,CAAC,KAAK,CA8BT,CAAA"}
|
|
@@ -1,81 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Events, makeSchema, State } from '@livestore/common/schema';
|
|
5
|
-
import { createStore } from '@livestore/livestore';
|
|
6
|
-
import { omitUndefineds } from '@livestore/utils';
|
|
7
|
-
import { Effect, Schema } from '@livestore/utils/effect';
|
|
2
|
+
import { createTodoMvcStore, events, schema, tables, } from '@livestore/framework-toolkit/testing';
|
|
3
|
+
import { Effect } from '@livestore/utils/effect';
|
|
8
4
|
import React from 'react';
|
|
9
5
|
import * as LiveStoreReact from "../mod.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
columns: {
|
|
13
|
-
id: State.SQLite.text({ primaryKey: true }),
|
|
14
|
-
text: State.SQLite.text({ default: '', nullable: false }),
|
|
15
|
-
completed: State.SQLite.boolean({ default: false, nullable: false }),
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const app = State.SQLite.table({
|
|
19
|
-
name: 'app',
|
|
20
|
-
columns: {
|
|
21
|
-
id: State.SQLite.text({ primaryKey: true, default: 'static' }),
|
|
22
|
-
newTodoText: State.SQLite.text({ default: '', nullable: true }),
|
|
23
|
-
filter: State.SQLite.text({ default: 'all', nullable: false }),
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
const userInfo = State.SQLite.clientDocument({
|
|
27
|
-
name: 'UserInfo',
|
|
28
|
-
schema: Schema.Struct({
|
|
29
|
-
username: Schema.String,
|
|
30
|
-
text: Schema.String,
|
|
31
|
-
}),
|
|
32
|
-
default: { value: { username: '', text: '' } },
|
|
33
|
-
});
|
|
34
|
-
const AppRouterSchema = State.SQLite.clientDocument({
|
|
35
|
-
name: 'AppRouter',
|
|
36
|
-
schema: Schema.Struct({
|
|
37
|
-
currentTaskId: Schema.String.pipe(Schema.NullOr),
|
|
38
|
-
}),
|
|
39
|
-
default: {
|
|
40
|
-
value: { currentTaskId: null },
|
|
41
|
-
id: 'singleton',
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
const kv = State.SQLite.clientDocument({
|
|
45
|
-
name: 'Kv',
|
|
46
|
-
schema: Schema.Any,
|
|
47
|
-
default: { value: null },
|
|
48
|
-
});
|
|
49
|
-
export const events = {
|
|
50
|
-
todoCreated: Events.synced({
|
|
51
|
-
name: 'todoCreated',
|
|
52
|
-
schema: Schema.Struct({ id: Schema.String, text: Schema.String, completed: Schema.Boolean }),
|
|
53
|
-
}),
|
|
54
|
-
todoUpdated: Events.synced({
|
|
55
|
-
name: 'todoUpdated',
|
|
56
|
-
schema: Schema.Struct({
|
|
57
|
-
id: Schema.String,
|
|
58
|
-
text: Schema.String.pipe(Schema.optional),
|
|
59
|
-
completed: Schema.Boolean.pipe(Schema.optional),
|
|
60
|
-
}),
|
|
61
|
-
}),
|
|
62
|
-
AppRouterSet: AppRouterSchema.set,
|
|
63
|
-
UserInfoSet: userInfo.set,
|
|
64
|
-
KvSet: kv.set,
|
|
65
|
-
};
|
|
66
|
-
const materializers = State.SQLite.materializers(events, {
|
|
67
|
-
todoCreated: ({ id, text, completed }) => todos.insert({ id, text, completed }),
|
|
68
|
-
todoUpdated: ({ id, text, completed }) => todos.update({ ...omitUndefineds({ completed, text }) }).where({ id }),
|
|
69
|
-
});
|
|
70
|
-
export const tables = { todos, app, userInfo, AppRouterSchema, kv };
|
|
71
|
-
const state = State.SQLite.makeState({ tables, materializers });
|
|
72
|
-
export const schema = makeSchema({ state, events });
|
|
6
|
+
// Re-export shared types and schema
|
|
7
|
+
export { events, schema, tables };
|
|
73
8
|
export const makeTodoMvcReact = (opts = {}) => Effect.gen(function* () {
|
|
74
9
|
const { strictMode } = opts;
|
|
75
10
|
const makeRenderCount = () => {
|
|
76
11
|
let val = 0;
|
|
77
12
|
const inc = () => {
|
|
78
|
-
val += strictMode ? 0.5 : 1;
|
|
13
|
+
val += strictMode === true ? 0.5 : 1;
|
|
79
14
|
};
|
|
80
15
|
return {
|
|
81
16
|
get val() {
|
|
@@ -84,16 +19,11 @@ export const makeTodoMvcReact = (opts = {}) => Effect.gen(function* () {
|
|
|
84
19
|
inc,
|
|
85
20
|
};
|
|
86
21
|
};
|
|
87
|
-
const store = yield*
|
|
88
|
-
schema,
|
|
89
|
-
storeId: 'default',
|
|
90
|
-
adapter: makeInMemoryAdapter(),
|
|
91
|
-
debug: { instanceId: 'test' },
|
|
92
|
-
});
|
|
22
|
+
const store = yield* createTodoMvcStore(opts);
|
|
93
23
|
const storeWithReactApi = LiveStoreReact.withReactApi(store);
|
|
94
|
-
const MaybeStrictMode = strictMode ? React.StrictMode : React.Fragment;
|
|
24
|
+
const MaybeStrictMode = strictMode === true ? React.StrictMode : React.Fragment;
|
|
95
25
|
const wrapper = ({ children }) => _jsx(MaybeStrictMode, { children: children });
|
|
96
26
|
const renderCount = makeRenderCount();
|
|
97
27
|
return { wrapper, store: storeWithReactApi, renderCount };
|
|
98
|
-
})
|
|
28
|
+
});
|
|
99
29
|
//# sourceMappingURL=fixture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":";AACA,OAAO,EAGL,kBAAkB,EAClB,MAAM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A;AAC3D,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAE1C,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAA;IACnG,+CAA+C;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACvD,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,EAAG,uCAAuC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAE1C,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAA;IACnG,+CAA+C;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACvD,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,EAAG,uCAAuC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,SAuCpG,CAAA"}
|
|
@@ -22,15 +22,16 @@ export const LiveList = ({ items$, renderItem, getKey, store }) => {
|
|
|
22
22
|
deps: [key],
|
|
23
23
|
}),
|
|
24
24
|
]), [getKey, items$, keys]);
|
|
25
|
-
return (_jsx(_Fragment, { children: arr.map(([key, item$], index) => (_jsx(ItemWrapperMemo, { itemKey: key, "item$": item$, store: store,
|
|
25
|
+
return (_jsx(_Fragment, { children: arr.map(([key, item$], index) => (_jsx(ItemWrapperMemo, { itemKey: key, "item$": item$, store: store, index: index, isInitialListRender: !hasMounted, renderItem: renderItem }, key))) }));
|
|
26
26
|
};
|
|
27
|
-
const ItemWrapper = ({ item$,
|
|
27
|
+
const ItemWrapper = ({ item$, index, isInitialListRender, renderItem, store, }) => {
|
|
28
28
|
const item = useQuery(item$, { store });
|
|
29
|
+
const opts = React.useMemo(() => ({ index, isInitialListRender }), [index, isInitialListRender]);
|
|
29
30
|
return _jsx(_Fragment, { children: renderItem(item, opts) });
|
|
30
31
|
};
|
|
31
32
|
const ItemWrapperMemo = React.memo(ItemWrapper, (prev, next) => prev.itemKey === next.itemKey &&
|
|
32
33
|
prev.renderItem === next.renderItem &&
|
|
33
34
|
prev.store === next.store &&
|
|
34
|
-
prev.
|
|
35
|
-
prev.
|
|
35
|
+
prev.index === next.index &&
|
|
36
|
+
prev.isInitialListRender === next.isInitialListRender);
|
|
36
37
|
//# sourceMappingURL=LiveList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveList.js","sourceRoot":"","sources":["../../../src/experimental/components/LiveList.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAkB5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAwB,EAAmB,EAAE;IAC/G,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEzD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IAE9C,MAAM,IAAI,GAAG,QAAQ,CACnB,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAC1C,EAAE,KAAK,EAAE,CACV,CAAA;IACD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CACvB,GAAG,EAAE,CACH,IAAI,CAAC,GAAG,CACN,CAAC,GAAG,EAAE,EAAE;IACN,+GAA+G;IAC/G;QACE,GAAG;QACH,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,GAAG,CAAE,EAAE;YACtE,IAAI,EAAE,CAAC,GAAG,CAAC;SACZ,CAAwB;KACjB,CACb,EACH,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CACvB,CAAA;IAED,OAAO,CACL,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A"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export type { Dispatch, SetStateAction, SetStateActionPartial, StateSetters } from '@livestore/framework-toolkit';
|
|
2
|
+
export { captureStackInfo } from '@livestore/framework-toolkit';
|
|
1
3
|
export { StoreRegistry, storeOptions } from '@livestore/livestore';
|
|
2
4
|
export { LiveList, type LiveListProps } from './experimental/components/LiveList.tsx';
|
|
3
5
|
export * from './StoreRegistryContext.tsx';
|
|
4
|
-
export { type
|
|
6
|
+
export { type UseClientDocumentResult, useClientDocument } from './useClientDocument.ts';
|
|
5
7
|
export { useQuery, useQueryRef } from './useQuery.ts';
|
|
6
8
|
export { type ReactApi, useStore, withReactApi } from './useStore.ts';
|
|
7
|
-
export {
|
|
9
|
+
export { useSyncStatus } from './useSyncStatus.ts';
|
|
8
10
|
//# sourceMappingURL=mod.d.ts.map
|
package/dist/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,wCAAwC,CAAA;AACrF,cAAc,4BAA4B,CAAA;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,wCAAwC,CAAA;AACrF,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,KAAK,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,KAAK,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/mod.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export { captureStackInfo } from '@livestore/framework-toolkit';
|
|
1
2
|
export { StoreRegistry, storeOptions } from '@livestore/livestore';
|
|
2
3
|
export { LiveList } from "./experimental/components/LiveList.js";
|
|
3
4
|
export * from "./StoreRegistryContext.js";
|
|
4
|
-
export { useClientDocument
|
|
5
|
+
export { useClientDocument } from "./useClientDocument.js";
|
|
5
6
|
export { useQuery, useQueryRef } from "./useQuery.js";
|
|
6
7
|
export { useStore, withReactApi } from "./useStore.js";
|
|
7
|
-
export {
|
|
8
|
+
export { useSyncStatus } from "./useSyncStatus.js";
|
|
8
9
|
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAsB,MAAM,uCAAwC,CAAA;AACrF,cAAc,2BAA4B,CAAA;AAC1C,OAAO,EAAgC,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAiB,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RowQuery } from '@livestore/common';
|
|
2
2
|
import { SessionIdSymbol } from '@livestore/common';
|
|
3
3
|
import { State } from '@livestore/common/schema';
|
|
4
|
+
import { type StateSetters } from '@livestore/framework-toolkit';
|
|
4
5
|
import type { LiveQuery } from '@livestore/livestore';
|
|
5
6
|
/**
|
|
6
7
|
* Return type of `useClientDocument` hook.
|
|
@@ -62,30 +63,4 @@ export declare const useClientDocument: {
|
|
|
62
63
|
default: any;
|
|
63
64
|
}>>(table: TTableDef, id: State.SQLite.ClientDocumentTableDef.DefaultIdType<TTableDef> | string | SessionIdSymbol, options?: Partial<RowQuery.GetOrCreateOptions<TTableDef>>): UseClientDocumentResult<TTableDef>;
|
|
64
65
|
};
|
|
65
|
-
/**
|
|
66
|
-
* A function that dispatches an action. Mirrors React's `Dispatch` type.
|
|
67
|
-
* @typeParam A - The action type
|
|
68
|
-
*/
|
|
69
|
-
export type Dispatch<A> = (action: A) => void;
|
|
70
|
-
/**
|
|
71
|
-
* A state update that can be either a partial value or a function returning a partial value.
|
|
72
|
-
* Used when the client-document table has `partialSet: true`.
|
|
73
|
-
* @typeParam S - The state type
|
|
74
|
-
*/
|
|
75
|
-
export type SetStateActionPartial<S> = Partial<S> | ((previousValue: S) => Partial<S>);
|
|
76
|
-
/**
|
|
77
|
-
* A state update that can be either a full value or a function returning a full value.
|
|
78
|
-
* Mirrors React's `SetStateAction` type.
|
|
79
|
-
* @typeParam S - The state type
|
|
80
|
-
*/
|
|
81
|
-
export type SetStateAction<S> = S | ((previousValue: S) => S);
|
|
82
|
-
/**
|
|
83
|
-
* The setter function type for `useClientDocument`, determined by the table's `partialSet` option.
|
|
84
|
-
*
|
|
85
|
-
* - If `partialSet: false` (default), requires full state replacement
|
|
86
|
-
* - If `partialSet: true`, accepts partial updates merged with existing state
|
|
87
|
-
*
|
|
88
|
-
* @typeParam TTableDef - The client-document table definition type
|
|
89
|
-
*/
|
|
90
|
-
export type StateSetters<TTableDef extends State.SQLite.ClientDocumentTableDef.TraitAny> = Dispatch<TTableDef[State.SQLite.ClientDocumentTableDefSymbol]['options']['partialSet'] extends false ? SetStateAction<TTableDef['Value']> : SetStateActionPartial<TTableDef['Value']>>;
|
|
91
66
|
//# sourceMappingURL=useClientDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientDocument.d.ts","sourceRoot":"","sources":["../src/useClientDocument.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useClientDocument.d.ts","sourceRoot":"","sources":["../src/useClientDocument.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAyB,KAAK,YAAY,EAAwB,MAAM,8BAA8B,CAAA;AAC7G,OAAO,KAAK,EAAE,SAAS,EAAuB,MAAM,sBAAsB,CAAA;AAM1E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,uBAAuB,CAAC,SAAS,SAAS,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,QAAQ,IAAI;IACpG,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC;IAC/B,EAAE,EAAE,MAAM;IACV,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;CACtC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,iBAAiB,EAAE;IAE9B,CACE,SAAS,SAAS,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,KAAK,CACzD,GAAG,EACH,GAAG,EACH,GAAG,EACH;QACE,UAAU,EAAE,OAAO,CAAA;QACnB,kFAAkF;QAClF,OAAO,EAAE,GAAG,CAAA;KACb,CACF,EAED,KAAK,EAAE,SAAS,EAChB,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,eAAe,EACnF,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,GACxD,uBAAuB,CAAC,SAAS,CAAC,CAAA;IAGrC,CACE,SAAS,SAAS,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,KAAK,CACzD,GAAG,EACH,GAAG,EACH,GAAG,EACH;QACE,UAAU,EAAE,OAAO,CAAA;QACnB,kFAAkF;QAClF,OAAO,EAAE,GAAG,CAAA;KACb,CACF,EAED,KAAK,EAAE,SAAS,EAEhB,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,eAAe,EAC3F,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,GACxD,uBAAuB,CAAC,SAAS,CAAC,CAAA;CAkDtC,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { SessionIdSymbol } from '@livestore/common';
|
|
2
3
|
import { State } from '@livestore/common/schema';
|
|
4
|
+
import { removeUndefinedValues, validateTableOptions } from '@livestore/framework-toolkit';
|
|
3
5
|
import { queryDb } from '@livestore/livestore';
|
|
4
6
|
import { omitUndefineds, shouldNeverHappen } from '@livestore/utils';
|
|
5
|
-
import React from 'react';
|
|
6
7
|
import { useQueryRef } from "./useQuery.js";
|
|
7
8
|
/**
|
|
8
9
|
* Similar to `React.useState` but returns a tuple of `[state, setState, id, query$]` for a given table where ...
|
|
@@ -44,7 +45,6 @@ export const useClientDocument = (table, idOrOptions, options_, storeArg) => {
|
|
|
44
45
|
React.useMemo(() => validateTableOptions(table), [table]);
|
|
45
46
|
const tableName = table.sqliteDef.name;
|
|
46
47
|
const store = storeArg?.store ?? shouldNeverHappen(`No store provided to useClientDocument`);
|
|
47
|
-
// console.debug('useClientDocument', tableName, id)
|
|
48
48
|
const idStr = id === SessionIdSymbol ? store.sessionId : id;
|
|
49
49
|
const queryDef = React.useMemo(() => queryDb(table.get(id, { default: defaultValues }), {
|
|
50
50
|
deps: [idStr, table.sqliteDef.name, JSON.stringify(defaultValues)],
|
|
@@ -61,15 +61,4 @@ export const useClientDocument = (table, idOrOptions, options_, storeArg) => {
|
|
|
61
61
|
}, [id, queryRef.valueRef, store, table]);
|
|
62
62
|
return [queryRef.valueRef.current, setState, idStr, queryRef.queryRcRef.value];
|
|
63
63
|
};
|
|
64
|
-
const validateTableOptions = (table) => {
|
|
65
|
-
if (State.SQLite.tableIsClientDocumentTable(table) === false) {
|
|
66
|
-
return shouldNeverHappen(`useClientDocument called on table "${table.sqliteDef.name}" which is not a client document table`);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const removeUndefinedValues = (value) => {
|
|
70
|
-
if (typeof value === 'object' && value !== null) {
|
|
71
|
-
return Object.fromEntries(Object.entries(value).filter(([_, v]) => v !== undefined));
|
|
72
|
-
}
|
|
73
|
-
return value;
|
|
74
|
-
};
|
|
75
64
|
//# sourceMappingURL=useClientDocument.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientDocument.js","sourceRoot":"","sources":["../src/useClientDocument.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useClientDocument.js","sourceRoot":"","sources":["../src/useClientDocument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAE,qBAAqB,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