@livestore/react 0.4.0-dev.9 → 0.4.0
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 +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 +12 -283
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +12 -86
- 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 +10 -8
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/mod.d.ts +8 -5
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +6 -4
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts +12 -4
- package/dist/useClientDocument.d.ts.map +1 -1
- package/dist/useClientDocument.js +4 -18
- package/dist/useClientDocument.js.map +1 -1
- package/dist/useClientDocument.test.js +21 -9
- package/dist/useClientDocument.test.js.map +1 -1
- package/dist/useQuery.d.ts +29 -8
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +43 -70
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +57 -13
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useRcResource.d.ts +1 -1
- package/dist/useRcResource.d.ts.map +1 -1
- package/dist/useRcResource.js +41 -34
- package/dist/useRcResource.js.map +1 -1
- package/dist/useRcResource.test.js +72 -50
- package/dist/useRcResource.test.js.map +1 -1
- package/dist/useStore.d.ts +74 -7
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +82 -16
- package/dist/useStore.js.map +1 -1
- package/dist/useStore.test.d.ts +2 -0
- package/dist/useStore.test.d.ts.map +1 -0
- package/dist/useStore.test.js +241 -0
- package/dist/useStore.test.js.map +1 -0
- 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 +69 -26
- package/src/StoreRegistryContext.tsx +70 -0
- package/src/__snapshots__/useClientDocument.test.tsx.snap +112 -78
- package/src/__snapshots__/useQuery.test.tsx.snap +12 -12
- package/src/__tests__/fixture.tsx +29 -133
- package/src/experimental/components/LiveList.tsx +23 -10
- package/src/mod.ts +8 -12
- package/src/useClientDocument.test.tsx +90 -79
- package/src/useClientDocument.ts +19 -38
- package/src/useQuery.test.tsx +99 -13
- package/src/useQuery.ts +74 -89
- package/src/useRcResource.test.tsx +115 -59
- package/src/useRcResource.ts +51 -37
- package/src/useStore.test.tsx +347 -0
- package/src/useStore.ts +115 -22
- package/src/useSyncStatus.ts +34 -0
- 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 -65
- package/dist/LiveStoreProvider.d.ts.map +0 -1
- package/dist/LiveStoreProvider.js +0 -221
- 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/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/LiveStoreContext.ts +0 -14
- package/src/LiveStoreProvider.test.tsx +0 -248
- package/src/LiveStoreProvider.tsx +0 -413
- package/src/ambient.d.ts +0 -1
- package/src/utils/stack-info.ts +0 -13
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import type { Store, SyncStatus } from '@livestore/livestore'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook that subscribes to sync status changes.
|
|
7
|
+
*
|
|
8
|
+
* Returns the current synchronization status between the client session and
|
|
9
|
+
* the leader thread. The component re-renders whenever the sync status changes.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function SyncIndicator() {
|
|
14
|
+
* const status = store.useSyncStatus()
|
|
15
|
+
* return <span>{status.isSynced ? '✓ Synced' : `Syncing (${status.pendingCount} pending)...`}</span>
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param options - Options containing the store instance
|
|
20
|
+
* @returns The current sync status
|
|
21
|
+
*/
|
|
22
|
+
export const useSyncStatus = (options: { store: Store<any> }): SyncStatus => {
|
|
23
|
+
const { store } = options
|
|
24
|
+
|
|
25
|
+
const [status, setStatus] = React.useState<SyncStatus>(() => store.syncStatus())
|
|
26
|
+
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
return store.subscribeSyncStatus(setStatus)
|
|
29
|
+
}, [store])
|
|
30
|
+
|
|
31
|
+
React.useDebugValue(`LiveStore:useSyncStatus:${status.isSynced === true ? 'synced' : 'pending'}`)
|
|
32
|
+
|
|
33
|
+
return status
|
|
34
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LiveStoreContextRunning } from '@livestore/livestore';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import type { useClientDocument } from './useClientDocument.ts';
|
|
4
|
-
import type { useQuery } from './useQuery.ts';
|
|
5
|
-
export type ReactApi = {
|
|
6
|
-
useQuery: typeof useQuery;
|
|
7
|
-
useClientDocument: typeof useClientDocument;
|
|
8
|
-
};
|
|
9
|
-
export declare const LiveStoreContext: React.Context<{
|
|
10
|
-
stage: "running";
|
|
11
|
-
store: LiveStoreContextRunning["store"] & ReactApi;
|
|
12
|
-
} | undefined>;
|
|
13
|
-
//# sourceMappingURL=LiveStoreContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreContext.d.ts","sourceRoot":"","sources":["../src/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,OAAO,QAAQ,CAAA;IACzB,iBAAiB,EAAE,OAAO,iBAAiB,CAAA;CAC5C,CAAA;AAED,eAAO,MAAM,gBAAgB;WAClB,SAAS;WAAS,uBAAuB,CAAC,OAAO,CAAC,GAAG,QAAQ;cAC5D,CAAA"}
|
package/dist/LiveStoreContext.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreContext.js","sourceRoot":"","sources":["../src/LiveStoreContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAEjD,SAAS,CAAC,CAAA"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Adapter, BootStatus, IntentionalShutdownCause, MigrationsReport, SyncError } from '@livestore/common';
|
|
2
|
-
import { UnexpectedError } from '@livestore/common';
|
|
3
|
-
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
4
|
-
import type { OtelOptions, Store } from '@livestore/livestore';
|
|
5
|
-
import { StoreInterrupted } from '@livestore/livestore';
|
|
6
|
-
import type { OtelTracer } from '@livestore/utils/effect';
|
|
7
|
-
import { Effect, Schema } from '@livestore/utils/effect';
|
|
8
|
-
import type * as otel from '@opentelemetry/api';
|
|
9
|
-
import React from 'react';
|
|
10
|
-
export interface LiveStoreProviderProps {
|
|
11
|
-
schema: LiveStoreSchema;
|
|
12
|
-
/**
|
|
13
|
-
* The `storeId` can be used to isolate multiple stores from each other.
|
|
14
|
-
* So it can be useful for multi-tenancy scenarios.
|
|
15
|
-
*
|
|
16
|
-
* The `storeId` is also used for persistence.
|
|
17
|
-
*
|
|
18
|
-
* Make sure to also configure `storeId` in LiveStore Devtools (e.g. in Vite plugin).
|
|
19
|
-
*
|
|
20
|
-
* @default 'default'
|
|
21
|
-
*/
|
|
22
|
-
storeId?: string;
|
|
23
|
-
boot?: (store: Store<LiveStoreSchema>, ctx: {
|
|
24
|
-
migrationsReport: MigrationsReport;
|
|
25
|
-
parentSpan: otel.Span;
|
|
26
|
-
}) => void | Promise<void> | Effect.Effect<void, unknown, OtelTracer.OtelTracer>;
|
|
27
|
-
otelOptions?: Partial<OtelOptions>;
|
|
28
|
-
renderLoading?: (status: BootStatus) => React.ReactNode;
|
|
29
|
-
renderError?: (error: UnexpectedError | unknown) => React.ReactNode;
|
|
30
|
-
renderShutdown?: (cause: IntentionalShutdownCause | StoreInterrupted | SyncError) => React.ReactNode;
|
|
31
|
-
adapter: Adapter;
|
|
32
|
-
/**
|
|
33
|
-
* In order for LiveStore to apply multiple events in a single render,
|
|
34
|
-
* you need to pass the `batchUpdates` function from either `react-dom` or `react-native`.
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* // With React DOM
|
|
38
|
-
* import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
|
|
39
|
-
*
|
|
40
|
-
* // With React Native
|
|
41
|
-
* import { unstable_batchedUpdates as batchUpdates } from 'react-native'
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
batchUpdates: (run: () => void) => void;
|
|
45
|
-
disableDevtools?: boolean;
|
|
46
|
-
signal?: AbortSignal;
|
|
47
|
-
/**
|
|
48
|
-
* Currently only used in the web adapter:
|
|
49
|
-
* If true, registers a beforeunload event listener to confirm unsaved changes.
|
|
50
|
-
*
|
|
51
|
-
* @default true
|
|
52
|
-
*/
|
|
53
|
-
confirmUnsavedChanges?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Payload that will be passed to the sync backend when connecting
|
|
56
|
-
*
|
|
57
|
-
* @default undefined
|
|
58
|
-
*/
|
|
59
|
-
syncPayload?: Schema.JsonValue;
|
|
60
|
-
debug?: {
|
|
61
|
-
instanceId?: string;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export declare const LiveStoreProvider: ({ renderLoading, renderError, renderShutdown, otelOptions, children, schema, storeId, boot, adapter, batchUpdates, disableDevtools, signal, confirmUnsavedChanges, syncPayload, debug, }: LiveStoreProviderProps & React.PropsWithChildren) => React.ReactNode;
|
|
65
|
-
//# sourceMappingURL=LiveStoreProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACnH,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAEV,WAAW,EAEX,KAAK,EAEN,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAqC,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAGL,MAAM,EAKN,MAAM,EAGP,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,WAAW,sBAAsB;IACrC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|
|
1
|
-
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { provideOtel, UnexpectedError } 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, Logger, LogLevel, 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(UnexpectedError)(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, debug, }) => {
|
|
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
|
-
debug,
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
42
|
-
if (storeCtx.stage === 'error') {
|
|
43
|
-
return renderError(storeCtx.error);
|
|
44
|
-
}
|
|
45
|
-
if (storeCtx.stage === 'shutdown') {
|
|
46
|
-
return renderShutdown(storeCtx.cause);
|
|
47
|
-
}
|
|
48
|
-
if (storeCtx.stage !== 'running') {
|
|
49
|
-
return renderLoading(storeCtx);
|
|
50
|
-
}
|
|
51
|
-
globalThis.__debugLiveStore ??= {};
|
|
52
|
-
if (Object.keys(globalThis.__debugLiveStore).length === 0) {
|
|
53
|
-
globalThis.__debugLiveStore._ = storeCtx.store;
|
|
54
|
-
}
|
|
55
|
-
globalThis.__debugLiveStore[debug?.instanceId ?? storeId] = storeCtx.store;
|
|
56
|
-
return _jsx(LiveStoreContext.Provider, { value: storeCtx, children: children });
|
|
57
|
-
};
|
|
58
|
-
const useCreateStore = ({ schema, storeId, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, context, params, confirmUnsavedChanges, syncPayload, debug, }) => {
|
|
59
|
-
const [_, rerender] = React.useState(0);
|
|
60
|
-
const ctxValueRef = React.useRef({
|
|
61
|
-
value: { stage: 'loading' },
|
|
62
|
-
componentScope: undefined,
|
|
63
|
-
shutdownDeferred: undefined,
|
|
64
|
-
previousShutdownDeferred: undefined,
|
|
65
|
-
counter: 0,
|
|
66
|
-
});
|
|
67
|
-
const debugInstanceId = debug?.instanceId;
|
|
68
|
-
// console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
|
|
69
|
-
const inputPropsCacheRef = React.useRef({
|
|
70
|
-
schema,
|
|
71
|
-
otelOptions,
|
|
72
|
-
boot,
|
|
73
|
-
adapter,
|
|
74
|
-
batchUpdates,
|
|
75
|
-
disableDevtools,
|
|
76
|
-
signal,
|
|
77
|
-
context,
|
|
78
|
-
params,
|
|
79
|
-
confirmUnsavedChanges,
|
|
80
|
-
syncPayload,
|
|
81
|
-
debugInstanceId,
|
|
82
|
-
});
|
|
83
|
-
const interrupt = React.useCallback((componentScope, shutdownDeferred, error) => Effect.gen(function* () {
|
|
84
|
-
// console.log('[@livestore/livestore/react] interupting', error)
|
|
85
|
-
yield* Scope.close(componentScope, Exit.fail(error));
|
|
86
|
-
yield* Deferred.fail(shutdownDeferred, error);
|
|
87
|
-
}).pipe(Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] interupting', cause)), Effect.runFork), []);
|
|
88
|
-
const inputPropChanges = {
|
|
89
|
-
schema: inputPropsCacheRef.current.schema !== schema,
|
|
90
|
-
otelOptions: inputPropsCacheRef.current.otelOptions !== otelOptions,
|
|
91
|
-
boot: inputPropsCacheRef.current.boot !== boot,
|
|
92
|
-
adapter: inputPropsCacheRef.current.adapter !== adapter,
|
|
93
|
-
batchUpdates: inputPropsCacheRef.current.batchUpdates !== batchUpdates,
|
|
94
|
-
disableDevtools: inputPropsCacheRef.current.disableDevtools !== disableDevtools,
|
|
95
|
-
signal: inputPropsCacheRef.current.signal !== signal,
|
|
96
|
-
context: inputPropsCacheRef.current.context !== context,
|
|
97
|
-
params: inputPropsCacheRef.current.params !== params,
|
|
98
|
-
confirmUnsavedChanges: inputPropsCacheRef.current.confirmUnsavedChanges !== confirmUnsavedChanges,
|
|
99
|
-
syncPayload: inputPropsCacheRef.current.syncPayload !== syncPayload,
|
|
100
|
-
debugInstanceId: inputPropsCacheRef.current.debugInstanceId !== debugInstanceId,
|
|
101
|
-
};
|
|
102
|
-
if (inputPropChanges.schema ||
|
|
103
|
-
inputPropChanges.otelOptions ||
|
|
104
|
-
inputPropChanges.boot ||
|
|
105
|
-
inputPropChanges.adapter ||
|
|
106
|
-
inputPropChanges.batchUpdates ||
|
|
107
|
-
inputPropChanges.disableDevtools ||
|
|
108
|
-
inputPropChanges.signal ||
|
|
109
|
-
inputPropChanges.context ||
|
|
110
|
-
inputPropChanges.params ||
|
|
111
|
-
inputPropChanges.confirmUnsavedChanges ||
|
|
112
|
-
inputPropChanges.syncPayload) {
|
|
113
|
-
inputPropsCacheRef.current = {
|
|
114
|
-
schema,
|
|
115
|
-
otelOptions,
|
|
116
|
-
boot,
|
|
117
|
-
adapter,
|
|
118
|
-
batchUpdates,
|
|
119
|
-
disableDevtools,
|
|
120
|
-
signal,
|
|
121
|
-
context,
|
|
122
|
-
params,
|
|
123
|
-
confirmUnsavedChanges,
|
|
124
|
-
syncPayload,
|
|
125
|
-
debugInstanceId,
|
|
126
|
-
};
|
|
127
|
-
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
128
|
-
const changedInputProps = Object.keys(inputPropChanges).filter((key) => inputPropChanges[key]);
|
|
129
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: `re-rendering due to changed input props: ${changedInputProps.join(', ')}` }));
|
|
130
|
-
ctxValueRef.current.componentScope = undefined;
|
|
131
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
132
|
-
}
|
|
133
|
-
ctxValueRef.current = {
|
|
134
|
-
value: { stage: 'loading' },
|
|
135
|
-
componentScope: undefined,
|
|
136
|
-
shutdownDeferred: undefined,
|
|
137
|
-
previousShutdownDeferred: ctxValueRef.current.shutdownDeferred,
|
|
138
|
-
counter: ctxValueRef.current.counter + 1,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
React.useEffect(() => {
|
|
142
|
-
const counter = ctxValueRef.current.counter;
|
|
143
|
-
const setContextValue = (value) => {
|
|
144
|
-
if (ctxValueRef.current.counter !== counter)
|
|
145
|
-
return;
|
|
146
|
-
ctxValueRef.current.value = value;
|
|
147
|
-
rerender((c) => c + 1);
|
|
148
|
-
};
|
|
149
|
-
signal?.addEventListener('abort', () => {
|
|
150
|
-
if (ctxValueRef.current.componentScope !== undefined &&
|
|
151
|
-
ctxValueRef.current.shutdownDeferred !== undefined &&
|
|
152
|
-
ctxValueRef.current.counter === counter) {
|
|
153
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'Aborted via provided AbortController' }));
|
|
154
|
-
ctxValueRef.current.componentScope = undefined;
|
|
155
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
const cancel = Effect.gen(function* () {
|
|
159
|
-
// Wait for the previous store to fully shutdown before creating a new one
|
|
160
|
-
if (ctxValueRef.current.previousShutdownDeferred) {
|
|
161
|
-
yield* Deferred.await(ctxValueRef.current.previousShutdownDeferred);
|
|
162
|
-
}
|
|
163
|
-
const componentScope = yield* Scope.make().pipe(Effect.acquireRelease(Scope.close));
|
|
164
|
-
const shutdownDeferred = yield* makeShutdownDeferred;
|
|
165
|
-
ctxValueRef.current.componentScope = componentScope;
|
|
166
|
-
ctxValueRef.current.shutdownDeferred = shutdownDeferred;
|
|
167
|
-
yield* Effect.gen(function* () {
|
|
168
|
-
const store = yield* createStore({
|
|
169
|
-
schema,
|
|
170
|
-
storeId,
|
|
171
|
-
adapter,
|
|
172
|
-
shutdownDeferred,
|
|
173
|
-
...omitUndefineds({
|
|
174
|
-
boot,
|
|
175
|
-
batchUpdates,
|
|
176
|
-
disableDevtools,
|
|
177
|
-
context,
|
|
178
|
-
params,
|
|
179
|
-
confirmUnsavedChanges,
|
|
180
|
-
syncPayload,
|
|
181
|
-
}),
|
|
182
|
-
onBootStatus: (status) => {
|
|
183
|
-
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
|
|
184
|
-
return;
|
|
185
|
-
// NOTE sometimes when status come in in rapid succession, only the last value will be rendered by React
|
|
186
|
-
setContextValue(status);
|
|
187
|
-
},
|
|
188
|
-
debug: { ...omitUndefineds({ instanceId: debugInstanceId }) },
|
|
189
|
-
}).pipe(Effect.tapErrorCause((cause) => Deferred.failCause(shutdownDeferred, cause)));
|
|
190
|
-
setContextValue({ stage: 'running', store });
|
|
191
|
-
}).pipe(Scope.extend(componentScope), Effect.forkIn(componentScope));
|
|
192
|
-
const shutdownContext = (cause) => Effect.sync(() => setContextValue({ stage: 'shutdown', cause }));
|
|
193
|
-
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);
|
|
194
|
-
}).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' }), Effect.provide(Logger.prettyWithThread('window')), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runCallback);
|
|
195
|
-
return () => {
|
|
196
|
-
cancel();
|
|
197
|
-
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
198
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'unmounting component' }));
|
|
199
|
-
ctxValueRef.current.componentScope = undefined;
|
|
200
|
-
ctxValueRef.current.shutdownDeferred = undefined;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}, [
|
|
204
|
-
schema,
|
|
205
|
-
otelOptions,
|
|
206
|
-
boot,
|
|
207
|
-
adapter,
|
|
208
|
-
batchUpdates,
|
|
209
|
-
disableDevtools,
|
|
210
|
-
signal,
|
|
211
|
-
storeId,
|
|
212
|
-
context,
|
|
213
|
-
params,
|
|
214
|
-
confirmUnsavedChanges,
|
|
215
|
-
syncPayload,
|
|
216
|
-
debugInstanceId,
|
|
217
|
-
interrupt,
|
|
218
|
-
]);
|
|
219
|
-
return ctxValueRef.current.value;
|
|
220
|
-
};
|
|
221
|
-
//# sourceMappingURL=LiveStoreProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAShE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC1F,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEzF,OAAO,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,WAAW,GACZ,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAyDxD,MAAM,kBAAkB,GAAG,CAAC,KAAgC,EAAE,EAAE,CAC9D,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,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AAC,iBAAiB,EACxB,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EACzC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EACjD,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC1C,MAAM,CAAC,WAAW,CACnB,CAAA;QAED,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,CAAA;YAER,IAAI,WAAW,CAAC,OAAO,CAAC,cAAc,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;gBAC3G,SAAS,CACP,WAAW,CAAC,OAAO,CAAC,cAAc,EAClC,WAAW,CAAC,OAAO,CAAC,gBAAgB,EACpC,IAAI,gBAAgB,CAAC,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC,CACzD,CAAA;gBACD,WAAW,CAAC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAA;gBAC9C,WAAW,CAAC,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAA;YAClD,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE;QACD,MAAM;QACN,WAAW;QACX,IAAI;QACJ,OAAO;QACP,YAAY;QACZ,eAAe;QACf,MAAM;QACN,OAAO;QACP,OAAO;QACP,MAAM;QACN,qBAAqB;QACrB,WAAW;QACX,eAAe;QACf,SAAS;KACV,CAAC,CAAA;IAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;AAClC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.test.d.ts","sourceRoot":"","sources":["../src/LiveStoreProvider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -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 } 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.UnexpectedError')));
|
|
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.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('[]');
|
|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AAK,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack-info.d.ts","sourceRoot":"","sources":["../../src/utils/stack-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAGrF,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAEvD,eAAO,MAAM,YAAY,QAAO,SAOxB,CAAA"}
|
package/dist/utils/stack-info.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { extractStackInfoFromStackTrace } from '@livestore/livestore';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export const originalStackLimit = Error.stackTraceLimit;
|
|
4
|
-
export const useStackInfo = () => React.useMemo(() => {
|
|
5
|
-
Error.stackTraceLimit = 10;
|
|
6
|
-
const stack = new Error().stack;
|
|
7
|
-
Error.stackTraceLimit = originalStackLimit;
|
|
8
|
-
return extractStackInfoFromStackTrace(stack);
|
|
9
|
-
}, []);
|
|
10
|
-
//# sourceMappingURL=stack-info.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack-info.js","sourceRoot":"","sources":["../../src/utils/stack-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAkB,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAEvD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE,CAC1C,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;IACjB,KAAK,CAAC,eAAe,GAAG,EAAE,CAAA;IAE1B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAM,CAAA;IAChC,KAAK,CAAC,eAAe,GAAG,kBAAkB,CAAA;IAC1C,OAAO,8BAA8B,CAAC,KAAK,CAAC,CAAA;AAC9C,CAAC,EAAE,EAAE,CAAC,CAAA"}
|
package/src/LiveStoreContext.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LiveStoreContextRunning } from '@livestore/livestore'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import type { useClientDocument } from './useClientDocument.ts'
|
|
5
|
-
import type { useQuery } from './useQuery.ts'
|
|
6
|
-
|
|
7
|
-
export type ReactApi = {
|
|
8
|
-
useQuery: typeof useQuery
|
|
9
|
-
useClientDocument: typeof useClientDocument
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const LiveStoreContext = React.createContext<
|
|
13
|
-
{ stage: 'running'; store: LiveStoreContextRunning['store'] & ReactApi } | undefined
|
|
14
|
-
>(undefined)
|