@livestore/react 0.4.0-dev.20 → 0.4.0-dev.22
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/StoreRegistryContext.d.ts +56 -0
- package/dist/StoreRegistryContext.d.ts.map +1 -0
- package/dist/StoreRegistryContext.js +61 -0
- package/dist/StoreRegistryContext.js.map +1 -0
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +1 -6
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.d.ts +4 -2
- package/dist/experimental/components/LiveList.d.ts.map +1 -1
- package/dist/experimental/components/LiveList.js +6 -5
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/experimental/mod.d.ts +0 -1
- package/dist/experimental/mod.d.ts.map +1 -1
- package/dist/experimental/mod.js +0 -1
- package/dist/experimental/mod.js.map +1 -1
- package/dist/mod.d.ts +4 -3
- 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 +33 -0
- package/dist/useClientDocument.d.ts.map +1 -1
- package/dist/useClientDocument.js +1 -4
- package/dist/useClientDocument.js.map +1 -1
- package/dist/useQuery.d.ts +1 -1
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +2 -5
- package/dist/useQuery.js.map +1 -1
- package/dist/useStore.d.ts +62 -7
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +73 -15
- package/dist/useStore.js.map +1 -1
- package/dist/useStore.test.d.ts.map +1 -0
- package/dist/useStore.test.js +196 -0
- package/dist/useStore.test.js.map +1 -0
- package/package.json +7 -7
- package/src/StoreRegistryContext.tsx +69 -0
- package/src/__tests__/fixture.tsx +1 -13
- package/src/experimental/components/LiveList.tsx +13 -4
- package/src/experimental/mod.ts +0 -1
- package/src/mod.ts +4 -3
- package/src/useClientDocument.ts +36 -5
- package/src/useQuery.ts +2 -6
- package/src/useStore.test.tsx +271 -0
- package/src/useStore.ts +102 -23
- package/dist/LiveStoreContext.d.ts +0 -13
- package/dist/LiveStoreContext.d.ts.map +0 -1
- package/dist/LiveStoreContext.js +0 -3
- package/dist/LiveStoreContext.js.map +0 -1
- package/dist/LiveStoreProvider.d.ts +0 -66
- package/dist/LiveStoreProvider.d.ts.map +0 -1
- package/dist/LiveStoreProvider.js +0 -232
- package/dist/LiveStoreProvider.js.map +0 -1
- package/dist/LiveStoreProvider.test.d.ts +0 -2
- package/dist/LiveStoreProvider.test.d.ts.map +0 -1
- package/dist/LiveStoreProvider.test.js +0 -117
- package/dist/LiveStoreProvider.test.js.map +0 -1
- package/dist/experimental/multi-store/StoreRegistry.d.ts +0 -61
- package/dist/experimental/multi-store/StoreRegistry.d.ts.map +0 -1
- package/dist/experimental/multi-store/StoreRegistry.js +0 -275
- package/dist/experimental/multi-store/StoreRegistry.js.map +0 -1
- package/dist/experimental/multi-store/StoreRegistry.test.d.ts +0 -2
- package/dist/experimental/multi-store/StoreRegistry.test.d.ts.map +0 -1
- package/dist/experimental/multi-store/StoreRegistry.test.js +0 -464
- package/dist/experimental/multi-store/StoreRegistry.test.js.map +0 -1
- package/dist/experimental/multi-store/StoreRegistryContext.d.ts +0 -10
- package/dist/experimental/multi-store/StoreRegistryContext.d.ts.map +0 -1
- package/dist/experimental/multi-store/StoreRegistryContext.js +0 -15
- package/dist/experimental/multi-store/StoreRegistryContext.js.map +0 -1
- package/dist/experimental/multi-store/mod.d.ts +0 -6
- package/dist/experimental/multi-store/mod.d.ts.map +0 -1
- package/dist/experimental/multi-store/mod.js +0 -6
- package/dist/experimental/multi-store/mod.js.map +0 -1
- package/dist/experimental/multi-store/storeOptions.d.ts +0 -4
- package/dist/experimental/multi-store/storeOptions.d.ts.map +0 -1
- package/dist/experimental/multi-store/storeOptions.js +0 -4
- package/dist/experimental/multi-store/storeOptions.js.map +0 -1
- package/dist/experimental/multi-store/types.d.ts +0 -44
- package/dist/experimental/multi-store/types.d.ts.map +0 -1
- package/dist/experimental/multi-store/types.js +0 -2
- package/dist/experimental/multi-store/types.js.map +0 -1
- package/dist/experimental/multi-store/useStore.d.ts +0 -11
- package/dist/experimental/multi-store/useStore.d.ts.map +0 -1
- package/dist/experimental/multi-store/useStore.js +0 -21
- package/dist/experimental/multi-store/useStore.js.map +0 -1
- package/dist/experimental/multi-store/useStore.test.d.ts.map +0 -1
- package/dist/experimental/multi-store/useStore.test.js +0 -144
- package/dist/experimental/multi-store/useStore.test.js.map +0 -1
- package/src/LiveStoreContext.ts +0 -14
- package/src/LiveStoreProvider.test.tsx +0 -248
- package/src/LiveStoreProvider.tsx +0 -421
- package/src/experimental/multi-store/StoreRegistry.test.ts +0 -631
- package/src/experimental/multi-store/StoreRegistry.ts +0 -347
- package/src/experimental/multi-store/StoreRegistryContext.tsx +0 -23
- package/src/experimental/multi-store/mod.ts +0 -5
- package/src/experimental/multi-store/storeOptions.ts +0 -8
- package/src/experimental/multi-store/types.ts +0 -55
- package/src/experimental/multi-store/useStore.test.tsx +0 -197
- package/src/experimental/multi-store/useStore.ts +0 -34
- /package/dist/{experimental/multi-store/useStore.test.d.ts → useStore.test.d.ts} +0 -0
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { LogConfig, provideOtel, UnknownError } from '@livestore/common';
|
|
3
|
-
import { createStore, makeShutdownDeferred, StoreInterrupted } from '@livestore/livestore';
|
|
4
|
-
import { errorToString, IS_REACT_NATIVE, LS_DEV, omitUndefineds } from '@livestore/utils';
|
|
5
|
-
import { Cause, Deferred, Effect, Exit, identity, Schema, Scope, TaskTracing } from '@livestore/utils/effect';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import { LiveStoreContext } from "./LiveStoreContext.js";
|
|
8
|
-
const defaultRenderError = (error) => IS_REACT_NATIVE ? null : Schema.is(UnknownError)(error) ? error.toString() : errorToString(error);
|
|
9
|
-
const defaultRenderShutdown = (cause) => {
|
|
10
|
-
const reason = cause._tag === 'LiveStore.StoreInterrupted'
|
|
11
|
-
? `interrupted due to: ${cause.reason}`
|
|
12
|
-
: cause._tag === 'InvalidPushError' || cause._tag === 'InvalidPullError'
|
|
13
|
-
? `sync error: ${cause.cause}`
|
|
14
|
-
: cause.reason === 'devtools-import'
|
|
15
|
-
? 'devtools import'
|
|
16
|
-
: cause.reason === 'devtools-reset'
|
|
17
|
-
? 'devtools reset'
|
|
18
|
-
: cause.reason === 'adapter-reset'
|
|
19
|
-
? 'adapter reset'
|
|
20
|
-
: cause.reason === 'manual'
|
|
21
|
-
? 'manual shutdown'
|
|
22
|
-
: 'unknown reason';
|
|
23
|
-
return IS_REACT_NATIVE ? null : _jsxs(_Fragment, { children: ["LiveStore Shutdown due to ", reason] });
|
|
24
|
-
};
|
|
25
|
-
const defaultRenderLoading = (status) => IS_REACT_NATIVE ? null : _jsxs(_Fragment, { children: ["LiveStore is loading (", status.stage, ")..."] });
|
|
26
|
-
export const LiveStoreProvider = ({ renderLoading = defaultRenderLoading, renderError = defaultRenderError, renderShutdown = defaultRenderShutdown, otelOptions, children, schema, storeId = 'default', boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges = true, syncPayload, syncPayloadSchema, debug, logger, logLevel, }) => {
|
|
27
|
-
const storeCtx = useCreateStore({
|
|
28
|
-
storeId,
|
|
29
|
-
schema,
|
|
30
|
-
adapter,
|
|
31
|
-
batchUpdates,
|
|
32
|
-
confirmUnsavedChanges,
|
|
33
|
-
...omitUndefineds({
|
|
34
|
-
otelOptions,
|
|
35
|
-
boot,
|
|
36
|
-
disableDevtools,
|
|
37
|
-
signal,
|
|
38
|
-
syncPayload,
|
|
39
|
-
syncPayloadSchema,
|
|
40
|
-
debug,
|
|
41
|
-
}),
|
|
42
|
-
logger,
|
|
43
|
-
logLevel,
|
|
44
|
-
});
|
|
45
|
-
if (storeCtx.stage === 'error') {
|
|
46
|
-
return renderError(storeCtx.error);
|
|
47
|
-
}
|
|
48
|
-
if (storeCtx.stage === 'shutdown') {
|
|
49
|
-
return renderShutdown(storeCtx.cause);
|
|
50
|
-
}
|
|
51
|
-
if (storeCtx.stage !== 'running') {
|
|
52
|
-
return renderLoading(storeCtx);
|
|
53
|
-
}
|
|
54
|
-
globalThis.__debugLiveStore ??= {};
|
|
55
|
-
if (Object.keys(globalThis.__debugLiveStore).length === 0) {
|
|
56
|
-
globalThis.__debugLiveStore._ = storeCtx.store;
|
|
57
|
-
}
|
|
58
|
-
globalThis.__debugLiveStore[debug?.instanceId ?? storeId] = storeCtx.store;
|
|
59
|
-
return _jsx(LiveStoreContext.Provider, { value: storeCtx, children: children });
|
|
60
|
-
};
|
|
61
|
-
const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, context, params, confirmUnsavedChanges, syncPayload, syncPayloadSchema, debug, logger, logLevel, }) => {
|
|
62
|
-
const [_, rerender] = React.useState(0);
|
|
63
|
-
const ctxValueRef = React.useRef({
|
|
64
|
-
value: { stage: 'loading' },
|
|
65
|
-
componentScope: undefined,
|
|
66
|
-
shutdownDeferred: undefined,
|
|
67
|
-
previousShutdownDeferred: undefined,
|
|
68
|
-
counter: 0,
|
|
69
|
-
});
|
|
70
|
-
const debugInstanceId = debug?.instanceId;
|
|
71
|
-
// console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
|
|
72
|
-
const inputPropsCacheRef = React.useRef({
|
|
73
|
-
schema,
|
|
74
|
-
otelOptions,
|
|
75
|
-
boot,
|
|
76
|
-
adapter,
|
|
77
|
-
batchUpdates,
|
|
78
|
-
disableDevtools,
|
|
79
|
-
signal,
|
|
80
|
-
context,
|
|
81
|
-
params,
|
|
82
|
-
confirmUnsavedChanges,
|
|
83
|
-
syncPayload,
|
|
84
|
-
syncPayloadSchema,
|
|
85
|
-
debugInstanceId,
|
|
86
|
-
});
|
|
87
|
-
const interrupt = React.useCallback((componentScope, shutdownDeferred, error) => Effect.gen(function* () {
|
|
88
|
-
// console.log('[@livestore/livestore/react] interupting', error)
|
|
89
|
-
yield* Scope.close(componentScope, Exit.fail(error));
|
|
90
|
-
yield* Deferred.fail(shutdownDeferred, error);
|
|
91
|
-
}).pipe(Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] interupting', cause)), Effect.runFork), []);
|
|
92
|
-
const inputPropChanges = {
|
|
93
|
-
schema: inputPropsCacheRef.current.schema !== schema,
|
|
94
|
-
otelOptions: inputPropsCacheRef.current.otelOptions !== otelOptions,
|
|
95
|
-
boot: inputPropsCacheRef.current.boot !== boot,
|
|
96
|
-
adapter: inputPropsCacheRef.current.adapter !== adapter,
|
|
97
|
-
batchUpdates: inputPropsCacheRef.current.batchUpdates !== batchUpdates,
|
|
98
|
-
disableDevtools: inputPropsCacheRef.current.disableDevtools !== disableDevtools,
|
|
99
|
-
signal: inputPropsCacheRef.current.signal !== signal,
|
|
100
|
-
context: inputPropsCacheRef.current.context !== context,
|
|
101
|
-
params: inputPropsCacheRef.current.params !== params,
|
|
102
|
-
confirmUnsavedChanges: inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges,
|
|
103
|
-
syncPayload: inputPropsCacheRef.current.syncPayload !== syncPayload,
|
|
104
|
-
syncPayloadSchema: inputPropsCacheRef.current.syncPayloadSchema !== syncPayloadSchema,
|
|
105
|
-
debugInstanceId: inputPropsCacheRef.current.debugInstanceId !== debugInstanceId,
|
|
106
|
-
};
|
|
107
|
-
if (inputPropChanges.schema ||
|
|
108
|
-
inputPropChanges.otelOptions ||
|
|
109
|
-
inputPropChanges.boot ||
|
|
110
|
-
inputPropChanges.adapter ||
|
|
111
|
-
inputPropChanges.batchUpdates ||
|
|
112
|
-
inputPropChanges.disableDevtools ||
|
|
113
|
-
inputPropChanges.signal ||
|
|
114
|
-
inputPropChanges.context ||
|
|
115
|
-
inputPropChanges.params ||
|
|
116
|
-
inputPropChanges.confirmUnsavedChanges ||
|
|
117
|
-
inputPropChanges.syncPayload ||
|
|
118
|
-
inputPropChanges.syncPayloadSchema) {
|
|
119
|
-
inputPropsCacheRef.current = {
|
|
120
|
-
schema,
|
|
121
|
-
otelOptions,
|
|
122
|
-
boot,
|
|
123
|
-
adapter,
|
|
124
|
-
batchUpdates,
|
|
125
|
-
disableDevtools,
|
|
126
|
-
signal,
|
|
127
|
-
context,
|
|
128
|
-
params,
|
|
129
|
-
confirmUnsavedChanges,
|
|
130
|
-
syncPayload,
|
|
131
|
-
syncPayloadSchema,
|
|
132
|
-
debugInstanceId,
|
|
133
|
-
};
|
|
134
|
-
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
135
|
-
const changedInputProps = Object.keys(inputPropChanges).filter((key) => inputPropChanges[key]);
|
|
136
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: `re-rendering due to changed input props: ${changedInputProps.join(', ')}` }));
|
|
137
|
-
ctxValueRef.current.componentScope = undefined;
|
|
138
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
139
|
-
}
|
|
140
|
-
ctxValueRef.current = {
|
|
141
|
-
value: { stage: 'loading' },
|
|
142
|
-
componentScope: undefined,
|
|
143
|
-
shutdownDeferred: undefined,
|
|
144
|
-
previousShutdownDeferred: ctxValueRef.current.shutdownDeferred,
|
|
145
|
-
counter: ctxValueRef.current.counter + 1,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
React.useEffect(() => {
|
|
149
|
-
const counter = ctxValueRef.current.counter;
|
|
150
|
-
const setContextValue = (value) => {
|
|
151
|
-
if (ctxValueRef.current.counter !== counter)
|
|
152
|
-
return;
|
|
153
|
-
ctxValueRef.current.value = value;
|
|
154
|
-
rerender((c) => c + 1);
|
|
155
|
-
};
|
|
156
|
-
signal?.addEventListener('abort', () => {
|
|
157
|
-
if (ctxValueRef.current.componentScope !== undefined &&
|
|
158
|
-
ctxValueRef.current.shutdownDeferred !== undefined &&
|
|
159
|
-
ctxValueRef.current.counter === counter) {
|
|
160
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'Aborted via provided AbortController' }));
|
|
161
|
-
ctxValueRef.current.componentScope = undefined;
|
|
162
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const cancel = Effect.gen(function* () {
|
|
166
|
-
// Wait for the previous store to fully shutdown before creating a new one
|
|
167
|
-
if (ctxValueRef.current.previousShutdownDeferred) {
|
|
168
|
-
yield* Deferred.await(ctxValueRef.current.previousShutdownDeferred);
|
|
169
|
-
}
|
|
170
|
-
const componentScope = yield* Scope.make().pipe(Effect.acquireRelease(Scope.close));
|
|
171
|
-
const shutdownDeferred = yield* makeShutdownDeferred;
|
|
172
|
-
ctxValueRef.current.componentScope = componentScope;
|
|
173
|
-
ctxValueRef.current.shutdownDeferred = shutdownDeferred;
|
|
174
|
-
yield* Effect.gen(function* () {
|
|
175
|
-
const store = yield* createStore({
|
|
176
|
-
schema,
|
|
177
|
-
storeId,
|
|
178
|
-
adapter,
|
|
179
|
-
shutdownDeferred,
|
|
180
|
-
...omitUndefineds({
|
|
181
|
-
boot,
|
|
182
|
-
batchUpdates,
|
|
183
|
-
disableDevtools,
|
|
184
|
-
context,
|
|
185
|
-
params,
|
|
186
|
-
confirmUnsavedChanges,
|
|
187
|
-
syncPayload,
|
|
188
|
-
syncPayloadSchema,
|
|
189
|
-
}),
|
|
190
|
-
onBootStatus: (status) => {
|
|
191
|
-
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
|
|
192
|
-
return;
|
|
193
|
-
// NOTE sometimes when status come in in rapid succession, only the last value will be rendered by React
|
|
194
|
-
setContextValue(status);
|
|
195
|
-
},
|
|
196
|
-
debug: { ...omitUndefineds({ instanceId: debugInstanceId }) },
|
|
197
|
-
}).pipe(Effect.tapErrorCause((cause) => Deferred.failCause(shutdownDeferred, cause)));
|
|
198
|
-
setContextValue({ stage: 'running', store });
|
|
199
|
-
}).pipe(Scope.extend(componentScope), Effect.forkIn(componentScope));
|
|
200
|
-
const shutdownContext = (cause) => Effect.sync(() => setContextValue({ stage: 'shutdown', cause }));
|
|
201
|
-
yield* Deferred.await(shutdownDeferred).pipe(Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] shutdown', Cause.pretty(cause))), Effect.tap((intentionalShutdown) => shutdownContext(intentionalShutdown)), Effect.catchTag('InvalidPushError', (cause) => shutdownContext(cause)), Effect.catchTag('InvalidPullError', (cause) => shutdownContext(cause)), Effect.catchTag('LiveStore.StoreInterrupted', (cause) => shutdownContext(cause)), Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))), Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))), Effect.exit);
|
|
202
|
-
}).pipe(Effect.scoped, Effect.withSpan('@livestore/react:useCreateStore'), LS_DEV ? TaskTracing.withAsyncTaggingTracing((name) => console.createTask(name)) : identity, provideOtel(omitUndefineds({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer })), Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: 'window' }), LogConfig.withLoggerConfig({ logger, logLevel }, { threadName: 'window' }), Effect.runCallback);
|
|
203
|
-
return () => {
|
|
204
|
-
cancel();
|
|
205
|
-
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
206
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'unmounting component' }));
|
|
207
|
-
ctxValueRef.current.componentScope = undefined;
|
|
208
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}, [
|
|
212
|
-
schema,
|
|
213
|
-
otelOptions,
|
|
214
|
-
boot,
|
|
215
|
-
adapter,
|
|
216
|
-
batchUpdates,
|
|
217
|
-
disableDevtools,
|
|
218
|
-
signal,
|
|
219
|
-
storeId,
|
|
220
|
-
context,
|
|
221
|
-
params,
|
|
222
|
-
confirmUnsavedChanges,
|
|
223
|
-
syncPayload,
|
|
224
|
-
syncPayloadSchema,
|
|
225
|
-
debugInstanceId,
|
|
226
|
-
interrupt,
|
|
227
|
-
logger,
|
|
228
|
-
logLevel,
|
|
229
|
-
]);
|
|
230
|
-
return ctxValueRef.current.value;
|
|
231
|
-
};
|
|
232
|
-
//# sourceMappingURL=LiveStoreProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AASxE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC1F,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEzF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE7G,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AA2DxD,MAAM,kBAAkB,GAAG,CAAC,KAA6B,EAAE,EAAE,CAC3D,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAEnG,MAA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ings":""}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/** biome-ignore-all lint/a11y: test files need a11y disabled */
|
|
3
|
-
import { makeInMemoryAdapter } from '@livestore/adapter-web';
|
|
4
|
-
import { queryDb, StoreInternalsSymbol } from '@livestore/livestore';
|
|
5
|
-
import { Schema } from '@livestore/utils/effect';
|
|
6
|
-
import * as ReactTesting from '@testing-library/react';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import { unstable_batchedUpdates as batchUpdates } from 'react-dom';
|
|
9
|
-
import { describe, expect, it } from 'vitest';
|
|
10
|
-
import { events, schema, tables } from "./__tests__/fixture.js";
|
|
11
|
-
import { LiveStoreProvider } from "./LiveStoreProvider.js";
|
|
12
|
-
import * as LiveStoreReact from "./mod.js";
|
|
13
|
-
describe.each([true, false])('LiveStoreProvider (strictMode: %s)', (strictMode) => {
|
|
14
|
-
const WithStrictMode = strictMode ? React.StrictMode : React.Fragment;
|
|
15
|
-
it('simple', async () => {
|
|
16
|
-
let appRenderCount = 0;
|
|
17
|
-
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) });
|
|
18
|
-
const App = () => {
|
|
19
|
-
appRenderCount++;
|
|
20
|
-
const { store } = LiveStoreReact.useStore();
|
|
21
|
-
const todos = store.useQuery(allTodos$);
|
|
22
|
-
return _jsx("div", { children: JSON.stringify(todos) });
|
|
23
|
-
};
|
|
24
|
-
const abortController = new AbortController();
|
|
25
|
-
const Root = ({ forceUpdate }) => {
|
|
26
|
-
const bootCb = React.useCallback((store) => store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false })), []);
|
|
27
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: forceUpdate is used to force a re-render
|
|
28
|
-
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
29
|
-
return (_jsx(WithStrictMode, { children: _jsx(LiveStoreProvider, { schema: schema, renderLoading: (status) => _jsxs("div", { children: ["Loading LiveStore: ", status.stage] }), adapter: adapterMemo, boot: bootCb, signal: abortController.signal, batchUpdates: batchUpdates, children: _jsx(App, {}) }) }));
|
|
30
|
-
};
|
|
31
|
-
const { rerender } = ReactTesting.render(_jsx(Root, { forceUpdate: 1 }));
|
|
32
|
-
expect(appRenderCount).toBe(0);
|
|
33
|
-
await ReactTesting.waitForElementToBeRemoved(() => ReactTesting.screen.getByText((_) => _.startsWith('Loading LiveStore')));
|
|
34
|
-
expect(appRenderCount).toBe(strictMode ? 2 : 1);
|
|
35
|
-
rerender(_jsx(Root, { forceUpdate: 2 }));
|
|
36
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText('Loading LiveStore: loading'));
|
|
37
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText((_) => _.includes('buy milk')));
|
|
38
|
-
expect(appRenderCount).toBe(strictMode ? 4 : 2);
|
|
39
|
-
abortController.abort();
|
|
40
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText('LiveStore Shutdown due to interrupted', { exact: false }));
|
|
41
|
-
});
|
|
42
|
-
// TODO test aborting during boot
|
|
43
|
-
it('error during boot', async () => {
|
|
44
|
-
let appRenderCount = 0;
|
|
45
|
-
const App = () => {
|
|
46
|
-
appRenderCount++;
|
|
47
|
-
return _jsx("div", { children: "hello world" });
|
|
48
|
-
};
|
|
49
|
-
const Root = ({ forceUpdate }) => {
|
|
50
|
-
const bootCb = React.useCallback((_store) => {
|
|
51
|
-
// This should trigger an error because we're trying to insert invalid data
|
|
52
|
-
throw new Error('Simulated boot error');
|
|
53
|
-
}, []);
|
|
54
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: forceUpdate is used to force a re-render
|
|
55
|
-
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
56
|
-
return (_jsx(WithStrictMode, { children: _jsx(LiveStoreProvider, { schema: schema, renderLoading: (status) => _jsxs("div", { children: ["Loading LiveStore: ", status.stage] }), adapter: adapterMemo, boot: bootCb, batchUpdates: batchUpdates, children: _jsx(App, {}) }) }));
|
|
57
|
-
};
|
|
58
|
-
ReactTesting.render(_jsx(Root, { forceUpdate: 1 }));
|
|
59
|
-
expect(appRenderCount).toBe(0);
|
|
60
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText((_) => _.startsWith('LiveStore.UnknownError')));
|
|
61
|
-
});
|
|
62
|
-
it('unmounts when store is shutdown', async () => {
|
|
63
|
-
let appRenderCount = 0;
|
|
64
|
-
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) });
|
|
65
|
-
const shutdownDeferred = Promise.withResolvers();
|
|
66
|
-
const App = () => {
|
|
67
|
-
appRenderCount++;
|
|
68
|
-
const { store } = LiveStoreReact.useStore();
|
|
69
|
-
React.useEffect(() => {
|
|
70
|
-
shutdownDeferred.promise.then(() => {
|
|
71
|
-
console.log('shutdown');
|
|
72
|
-
return store.shutdown();
|
|
73
|
-
});
|
|
74
|
-
}, [store]);
|
|
75
|
-
const todos = store.useQuery(allTodos$);
|
|
76
|
-
return _jsx("div", { children: JSON.stringify(todos) });
|
|
77
|
-
};
|
|
78
|
-
const adapter = makeInMemoryAdapter();
|
|
79
|
-
const Root = () => {
|
|
80
|
-
return (_jsx(WithStrictMode, { children: _jsx(LiveStoreProvider, { schema: schema, renderLoading: (status) => _jsxs("div", { children: ["Loading LiveStore: ", status.stage] }), adapter: adapter, batchUpdates: batchUpdates, children: _jsx(App, {}) }) }));
|
|
81
|
-
};
|
|
82
|
-
ReactTesting.render(_jsx(Root, {}));
|
|
83
|
-
expect(appRenderCount).toBe(0);
|
|
84
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText('[]'));
|
|
85
|
-
React.act(() => shutdownDeferred.resolve());
|
|
86
|
-
expect(appRenderCount).toBe(strictMode ? 2 : 1);
|
|
87
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByText('LiveStore Shutdown due to manual shutdown', { exact: false }));
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
it('should work two stores with the same storeId', async () => {
|
|
91
|
-
const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) });
|
|
92
|
-
const appRenderCount = {
|
|
93
|
-
store1: 0,
|
|
94
|
-
store2: 0,
|
|
95
|
-
};
|
|
96
|
-
const App = () => {
|
|
97
|
-
const { store } = LiveStoreReact.useStore();
|
|
98
|
-
const instanceId = store[StoreInternalsSymbol].clientSession.debugInstanceId;
|
|
99
|
-
appRenderCount[instanceId]++;
|
|
100
|
-
const todos = store.useQuery(allTodos$);
|
|
101
|
-
return (_jsxs("div", { id: instanceId, children: [_jsx("div", { role: "heading", children: instanceId }), _jsx("div", { role: "content", children: JSON.stringify(todos) }), _jsxs("button", { onClick: () => store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false })), children: ["create todo ", instanceId] })] }));
|
|
102
|
-
};
|
|
103
|
-
const Root = () => {
|
|
104
|
-
const storeId = 'fixed-store-id';
|
|
105
|
-
return (_jsxs("div", { children: [_jsx(LiveStoreProvider, { storeId: storeId, debug: { instanceId: 'store1' }, schema: schema, adapter: makeInMemoryAdapter(), batchUpdates: batchUpdates, children: _jsx(App, {}) }), _jsx(LiveStoreProvider, { storeId: storeId, debug: { instanceId: 'store2' }, schema: schema, adapter: makeInMemoryAdapter(), batchUpdates: batchUpdates, children: _jsx(App, {}) })] }));
|
|
106
|
-
};
|
|
107
|
-
const { container } = ReactTesting.render(_jsx(Root, {}));
|
|
108
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByRole('heading', { name: 'store1' }));
|
|
109
|
-
await ReactTesting.waitFor(() => ReactTesting.screen.getByRole('heading', { name: 'store2' }));
|
|
110
|
-
expect(appRenderCount.store1).toBe(1);
|
|
111
|
-
expect(appRenderCount.store2).toBe(1);
|
|
112
|
-
ReactTesting.fireEvent.click(ReactTesting.screen.getByText('create todo store1'));
|
|
113
|
-
expect(appRenderCount.store1).toBe(2);
|
|
114
|
-
expect(container.querySelector('#store1 > div[role="content"]')?.textContent).toBe('[{"id":"t1","text":"buy milk","completed":false}]');
|
|
115
|
-
expect(container.querySelector('#store2 > div[role="content"]')?.textContent).toBe('[]');
|
|
116
|
-
});
|
|
117
|
-
//# sourceMappingURL=LiveStoreProvider.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.test.js","sourceRoot":"","sources":["../src/LiveStoreProvider.test.tsx"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAc,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,uBAAuB,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAyB,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAA;AAC3D,OAAO,KAAK,cAAc,MAAM,UAAU,CAAA;AAE1C,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,oCAAoC,EAAE,CAAC,UAAU,EAAE,EAAE;IAChF,MAAM,cAAc,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAA;IAErE,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtB,IAAI,cAAc,GAAG,CAAC,CAAA;QAEtB,MAAM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,CAAA;IAE9F,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACrC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAErC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAA;IAEjF,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAErC,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,+BAA+B,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAChF,mDAAmD,CACpD,CAAA;IAED,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,+BAA+B,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1F,CAAC,CAAC,CAAA"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
-
import { type Store, type Unsubscribe } from '@livestore/livestore';
|
|
3
|
-
import type { CachedStoreOptions, StoreId } from './types.ts';
|
|
4
|
-
type DefaultStoreOptions = Partial<Pick<CachedStoreOptions<any>, 'batchUpdates' | 'disableDevtools' | 'confirmUnsavedChanges' | 'syncPayload' | 'debug' | 'otelOptions'>> & {
|
|
5
|
-
/**
|
|
6
|
-
* The time in milliseconds that unused stores remain in memory.
|
|
7
|
-
* When a store becomes unused (no subscribers), it will be disposed
|
|
8
|
-
* after this duration.
|
|
9
|
-
*
|
|
10
|
-
* Stores transition to the unused state as soon as they have no
|
|
11
|
-
* subscriptions registered, so when all components which use that
|
|
12
|
-
* store have unmounted.
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* - If set to `Infinity`, will disable disposal
|
|
16
|
-
* - The maximum allowed time is about {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value | 24 days}
|
|
17
|
-
*
|
|
18
|
-
* @defaultValue `60_000` (60 seconds) or `Infinity` during SSR to avoid
|
|
19
|
-
* disposing stores before server render completes.
|
|
20
|
-
*/
|
|
21
|
-
unusedCacheTime?: number;
|
|
22
|
-
};
|
|
23
|
-
type StoreRegistryConfig = {
|
|
24
|
-
defaultOptions?: DefaultStoreOptions;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Store Registry coordinating store loading, caching, and subscription
|
|
28
|
-
*
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export declare class StoreRegistry {
|
|
32
|
-
#private;
|
|
33
|
-
constructor({ defaultOptions }?: StoreRegistryConfig);
|
|
34
|
-
/**
|
|
35
|
-
* Get or load a store, returning it directly if loaded or a promise if loading.
|
|
36
|
-
*
|
|
37
|
-
* @typeParam TSchema - The schema of the store to load
|
|
38
|
-
* @returns The loaded store if available, or a Promise that resolves to the loaded store
|
|
39
|
-
* @throws unknown loading error
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* - Returns the store instance directly (synchronous) when already loaded
|
|
43
|
-
* - Returns a stable Promise reference when loading is in progress or needs to be initiated
|
|
44
|
-
* - Applies default options from registry config, with call-site options taking precedence
|
|
45
|
-
*/
|
|
46
|
-
getOrLoad: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Store<TSchema> | Promise<Store<TSchema>>;
|
|
47
|
-
/**
|
|
48
|
-
* Warms the cache for a store without mounting a subscriber.
|
|
49
|
-
*
|
|
50
|
-
* @typeParam TSchema - The schema of the store to preload
|
|
51
|
-
* @returns A promise that resolves when the loading is complete (success or failure)
|
|
52
|
-
*
|
|
53
|
-
* @remarks
|
|
54
|
-
* - We don't return the store or throw as this is a fire-and-forget operation.
|
|
55
|
-
* - If the entry remains unused after preload resolves/rejects, it is scheduled for disposal.
|
|
56
|
-
*/
|
|
57
|
-
preload: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Promise<void>;
|
|
58
|
-
subscribe: <TSchema extends LiveStoreSchema>(storeId: StoreId, listener: () => void) => Unsubscribe;
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
61
|
-
//# sourceMappingURL=StoreRegistry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistry.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAsB,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AA2P7D,KAAK,mBAAmB,GAAG,OAAO,CAChC,IAAI,CACF,kBAAkB,CAAC,GAAG,CAAC,EACvB,cAAc,GAAG,iBAAiB,GAAG,uBAAuB,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,CACvG,CACF,GAAG;IACF;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC,CAAA;AAED;;;;GAIG;AACH,qBAAa,aAAa;;gBAIZ,EAAE,cAAmB,EAAE,GAAE,mBAAwB;IAW7D;;;;;;;;;;;OAWG;IACH,SAAS,GAAI,OAAO,SAAS,eAAe,EAC1C,SAAS,kBAAkB,CAAC,OAAO,CAAC,KACnC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAK1C;IAED;;;;;;;;;OASG;IACH,OAAO,GAAU,OAAO,SAAS,eAAe,EAAE,SAAS,kBAAkB,CAAC,OAAO,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC,CAMrG;IAED,SAAS,GAAI,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO,EAAE,UAAU,MAAM,IAAI,KAAG,WAAW,CAIjG;CACF"}
|