@livestore/react 0.4.0-dev.21 → 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 +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 +8 -280
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +9 -84
- 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 +9 -7
- 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 +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 +1 -26
- package/dist/useClientDocument.d.ts.map +1 -1
- package/dist/useClientDocument.js +3 -17
- 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 +4 -5
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +12 -85
- 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 +61 -46
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +75 -60
- package/dist/useStore.js.map +1 -1
- package/dist/useStore.test.d.ts.map +1 -0
- package/dist/{experimental/multi-store/useStore.test.js → useStore.test.js} +70 -27
- 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/__tests__/fixture.tsx +23 -118
- package/src/experimental/components/LiveList.tsx +22 -9
- package/src/experimental/mod.ts +0 -1
- package/src/mod.ts +8 -12
- package/src/useClientDocument.test.tsx +16 -6
- package/src/useClientDocument.ts +7 -61
- package/src/useQuery.test.tsx +8 -8
- package/src/useQuery.ts +30 -119
- package/src/useRcResource.test.tsx +1 -1
- package/src/useRcResource.ts +10 -5
- package/src/{experimental/multi-store/useStore.test.tsx → useStore.test.tsx} +117 -39
- package/src/useStore.ts +106 -65
- package/src/useSyncStatus.ts +34 -0
- package/dist/LiveStoreContext.d.ts +0 -40
- package/dist/LiveStoreContext.d.ts.map +0 -1
- package/dist/LiveStoreContext.js +0 -21
- package/dist/LiveStoreContext.js.map +0 -1
- package/dist/LiveStoreProvider.d.ts +0 -73
- package/dist/LiveStoreProvider.d.ts.map +0 -1
- package/dist/LiveStoreProvider.js +0 -233
- 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 -105
- package/dist/experimental/multi-store/StoreRegistry.d.ts.map +0 -1
- package/dist/experimental/multi-store/StoreRegistry.js +0 -184
- 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 -381
- 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 -25
- 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 -16
- 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.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 -41
- package/src/LiveStoreProvider.test.tsx +0 -248
- package/src/LiveStoreProvider.tsx +0 -430
- package/src/ambient.d.ts +0 -1
- package/src/experimental/multi-store/StoreRegistry.test.ts +0 -518
- package/src/experimental/multi-store/StoreRegistry.ts +0 -253
- 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 -37
- package/src/experimental/multi-store/useStore.ts +0 -26
- package/src/utils/stack-info.ts +0 -13
- /package/dist/{experimental/multi-store/useStore.test.d.ts → useStore.test.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRcResource.js","sourceRoot":"","sources":["../src/useRcResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,MAAe,EACf,OAAuC,EACvC,QAAwE,EACrE,EAAE;IACL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAqB,SAAS,CAAC,CAAA;IAC1D,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"useRcResource.js","sourceRoot":"","sources":["../src/useRcResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,MAAe,EACf,OAAuC,EACvC,QAAwE,EACrE,EAAE;IACL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAqB,SAAS,CAAC,CAAA;IAC1D,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACtC,MAAM,UAAU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G,GAAG,CAAA;IAEpB,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,0GAA0G;AAC1G,2FAA2F;AAC3F,2GAA2G;AAC3G,0FAA0F;AAC1F,MAAM,KAAK,GAAG,IAAI,GAAG,EAUlB,CAAA;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,KAAK,CAAC,KAAK,EAAE,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -6,7 +6,7 @@ describe.each([{ strictMode: true }, { strictMode: false }])('useRcResource (str
|
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
__resetUseRcResourceCache();
|
|
8
8
|
});
|
|
9
|
-
const wrapper = strictMode ? React.StrictMode : React.Fragment;
|
|
9
|
+
const wrapper = strictMode === true ? React.StrictMode : React.Fragment;
|
|
10
10
|
it('should create a stateful entity using make and call cleanup on unmount', () => {
|
|
11
11
|
const makeSpy = vi.fn(() => Symbol('statefulResource'));
|
|
12
12
|
const cleanupSpy = vi.fn();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRcResource.test.js","sourceRoot":"","sources":["../src/useRcResource.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7D,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAE7E,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,+BAA+B,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;IAC/G,UAAU,CAAC,GAAG,EAAE;QACd,yBAAyB,EAAE,CAAA;IAC7B,CAAC,CAAC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AG,EAAE,CAAC,CAAA;QAEtB,0DAA0D;QAC1D,MAAM,CAAC,OAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QACxC,6DAA6D;QAC7D,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QAE3C,OAAO,EAAE,CAAA;QACT,+DAA+D;QAC/D,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,4FAA4F;AAC5F,4BAA4B;AAC5B,4CAA4C;AAC5C,6BAA6B;AAC7B,+BAA+B;AAE/B,oCAAoC;AACpC,kCAAkC;AAClC,wBAAwB;AACxB,cAAc;AAEd,4BAA4B;AAC5B,oCAAoC;AACpC,qBAAqB;AACrB,oCAAoC;AACpC,QAAQ;AACR,WAAW;AAEX,aAAa;AACb,IAAI;AAEJ,wCAAwC;AACxC,2CAA2C;AAC3C,2BAA2B;AAC3B,2BAA2B;AAC3B,oBAAoB;AACpB,QAAQ;AACR,+CAA+C;AAC/C,2BAA2B;AAC3B,mBAAmB;AACnB,6BAA6B;AAC7B,QAAQ;AAER,gBAAgB;AAChB,OAAO;AAEP,mCAAmC;AACnC,sCAAsC;AACtC,gFAAgF;AAChF,yFAAyF;AAEzF,gBAAgB;AAChB,OAAO;AACP,KAAK"}
|
package/dist/useStore.d.ts
CHANGED
|
@@ -1,61 +1,76 @@
|
|
|
1
1
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
-
import type { Store } from '@livestore/livestore';
|
|
3
|
-
import type {
|
|
2
|
+
import type { RegistryStoreOptions, Store, SyncStatus } from '@livestore/livestore';
|
|
3
|
+
import type { Schema } from '@livestore/utils/effect';
|
|
4
|
+
import { useClientDocument } from './useClientDocument.ts';
|
|
5
|
+
import { useQuery } from './useQuery.ts';
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This is called automatically by `useStore()` and `LiveStoreProvider`. You typically
|
|
8
|
-
* don't need to call it directly unless you're building custom integrations.
|
|
7
|
+
* Returns a store instance augmented with hooks (`store.useQuery()` and `store.useClientDocument()`) for reactive queries.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export declare const withReactApi: <TSchema extends LiveStoreSchema>(store: Store<TSchema>) => Store<TSchema> & ReactApi;
|
|
18
|
-
/**
|
|
19
|
-
* Returns the current Store instance from React context, augmented with React-specific methods.
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function Issue() {
|
|
12
|
+
* // Suspends until loaded or returns immediately if already loaded
|
|
13
|
+
* const issueStore = useStore(issueStoreOptions('abc123'))
|
|
14
|
+
* const [issue] = issueStore.useQuery(queryDb(tables.issue.select()))
|
|
20
15
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
* const toggleStatus = () =>
|
|
17
|
+
* issueStore.commit(
|
|
18
|
+
* issueEvents.issueStatusChanged({
|
|
19
|
+
* id: issue.id,
|
|
20
|
+
* status: issue.status === 'done' ? 'todo' : 'done',
|
|
21
|
+
* }),
|
|
22
|
+
* )
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* const preloadParentIssue = (issueId: string) =>
|
|
25
|
+
* storeRegistry.preload({
|
|
26
|
+
* ...issueStoreOptions(issueId),
|
|
27
|
+
* unusedCacheTime: 10_000,
|
|
28
|
+
* })
|
|
26
29
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* return <button onClick={handleClick}>Add Todo</button>
|
|
30
|
+
* return (
|
|
31
|
+
* <>
|
|
32
|
+
* <h2>{issue.title}</h2>
|
|
33
|
+
* <button onClick={() => toggleStatus()}>Toggle Status</button>
|
|
34
|
+
* <button onMouseEnter={() => preloadParentIssue(issue.parentIssueId)}>Open Parent Issue</button>
|
|
35
|
+
* </>
|
|
36
|
+
* )
|
|
37
37
|
* }
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* ```
|
|
40
|
+
* @remarks
|
|
41
|
+
* - Suspends until the store is loaded.
|
|
42
|
+
* - Store is cached by its `storeId` in the `StoreRegistry`. Multiple calls with the same `storeId` return the same store instance.
|
|
43
|
+
* - Store is cached as long as it's being used, and after `unusedCacheTime` expires (default `60_000` ms in browser, `Infinity` in non-browser)
|
|
44
|
+
* - Default store options can be configured in `StoreRegistry` constructor.
|
|
45
|
+
* - Store options are only applied when the store is loaded. Subsequent calls with different options will not affect the store if it's already loaded and cached in the registry.
|
|
47
46
|
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
* @typeParam TSchema - The schema type for the store
|
|
48
|
+
* @returns The loaded store instance augmented with React hooks
|
|
49
|
+
* @throws unknown - store loading error or if called outside `<StoreRegistryProvider>`
|
|
50
|
+
*/
|
|
51
|
+
export declare const useStore: <TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>) => Store<TSchema, TContext> & ReactApi;
|
|
52
|
+
/**
|
|
53
|
+
* React-specific methods added to the Store when used via React hooks.
|
|
53
54
|
*
|
|
54
|
-
*
|
|
55
|
+
* These methods are attached by `withReactApi()` and `useStore()`, allowing you
|
|
56
|
+
* to call `store.useQuery()` and `store.useClientDocument()` directly on the
|
|
57
|
+
* Store instance.
|
|
55
58
|
*/
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
export type ReactApi = {
|
|
60
|
+
/** Hook version of query subscription—re-renders component when query result changes */
|
|
61
|
+
useQuery: typeof useQuery;
|
|
62
|
+
/** Hook for reading and writing client-document tables with React state semantics */
|
|
63
|
+
useClientDocument: typeof useClientDocument;
|
|
64
|
+
/** Hook for subscribing to sync status changes */
|
|
65
|
+
useSyncStatus: () => SyncStatus;
|
|
60
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Augments a Store instance with React-specific methods (`useQuery`, `useClientDocument`).
|
|
69
|
+
*
|
|
70
|
+
* This is called automatically by `useStore()`. You typically don't need to call it
|
|
71
|
+
* directly unless you're building custom integrations.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export declare const withReactApi: <TSchema extends LiveStoreSchema, TContext = {}>(store: Store<TSchema, TContext>) => Store<TSchema, TContext> & ReactApi;
|
|
61
76
|
//# sourceMappingURL=useStore.d.ts.map
|
package/dist/useStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,QAAQ,GACnB,OAAO,SAAS,eAAe,EAC/B,QAAQ,GAAG,EAAE,EACb,kBAAkB,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,MAAM,CAAC,SAAS,EAEvE,SAAS,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC,KACnE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,QA2B7B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,wFAAwF;IACxF,QAAQ,EAAE,OAAO,QAAQ,CAAA;IACzB,qFAAqF;IACrF,iBAAiB,EAAE,OAAO,iBAAiB,CAAA;IAC3C,kDAAkD;IAClD,aAAa,EAAE,MAAM,UAAU,CAAA;CAChC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,eAAe,EAAE,QAAQ,GAAG,EAAE,EACzE,OAAO,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,KAC9B,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,QAW7B,CAAA"}
|
package/dist/useStore.js
CHANGED
|
@@ -1,77 +1,92 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStoreRegistry } from "./StoreRegistryContext.js";
|
|
3
3
|
import { useClientDocument } from "./useClientDocument.js";
|
|
4
4
|
import { useQuery } from "./useQuery.js";
|
|
5
|
+
import { useSyncStatus } from "./useSyncStatus.js";
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This is called automatically by `useStore()` and `LiveStoreProvider`. You typically
|
|
9
|
-
* don't need to call it directly unless you're building custom integrations.
|
|
7
|
+
* Returns a store instance augmented with hooks (`store.useQuery()` and `store.useClientDocument()`) for reactive queries.
|
|
10
8
|
*
|
|
11
9
|
* @example
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
export const withReactApi = (store) => {
|
|
19
|
-
// @ts-expect-error TODO properly implement this
|
|
20
|
-
store.useQuery = (queryable) => useQuery(queryable, { store });
|
|
21
|
-
// @ts-expect-error TODO properly implement this
|
|
22
|
-
store.useClientDocument = (table, idOrOptions, options) => useClientDocument(table, idOrOptions, options, { store });
|
|
23
|
-
return store;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Returns the current Store instance from React context, augmented with React-specific methods.
|
|
27
|
-
*
|
|
28
|
-
* Use this hook when you need direct access to the Store for operations like
|
|
29
|
-
* `store.commit()`, `store.subscribe()`, or accessing `store.sessionId`.
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function Issue() {
|
|
12
|
+
* // Suspends until loaded or returns immediately if already loaded
|
|
13
|
+
* const issueStore = useStore(issueStoreOptions('abc123'))
|
|
14
|
+
* const [issue] = issueStore.useQuery(queryDb(tables.issue.select()))
|
|
30
15
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
16
|
+
* const toggleStatus = () =>
|
|
17
|
+
* issueStore.commit(
|
|
18
|
+
* issueEvents.issueStatusChanged({
|
|
19
|
+
* id: issue.id,
|
|
20
|
+
* status: issue.status === 'done' ? 'todo' : 'done',
|
|
21
|
+
* }),
|
|
22
|
+
* )
|
|
33
23
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* const handleClick = () => {
|
|
40
|
-
* store.commit(events.todoCreated({ id: nanoid(), text: 'New todo' }))
|
|
41
|
-
* }
|
|
24
|
+
* const preloadParentIssue = (issueId: string) =>
|
|
25
|
+
* storeRegistry.preload({
|
|
26
|
+
* ...issueStoreOptions(issueId),
|
|
27
|
+
* unusedCacheTime: 10_000,
|
|
28
|
+
* })
|
|
42
29
|
*
|
|
43
|
-
* return
|
|
30
|
+
* return (
|
|
31
|
+
* <>
|
|
32
|
+
* <h2>{issue.title}</h2>
|
|
33
|
+
* <button onClick={() => toggleStatus()}>Toggle Status</button>
|
|
34
|
+
* <button onMouseEnter={() => preloadParentIssue(issue.parentIssueId)}>Open Parent Issue</button>
|
|
35
|
+
* </>
|
|
36
|
+
* )
|
|
44
37
|
* }
|
|
45
38
|
* ```
|
|
46
39
|
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* ```
|
|
40
|
+
* @remarks
|
|
41
|
+
* - Suspends until the store is loaded.
|
|
42
|
+
* - Store is cached by its `storeId` in the `StoreRegistry`. Multiple calls with the same `storeId` return the same store instance.
|
|
43
|
+
* - Store is cached as long as it's being used, and after `unusedCacheTime` expires (default `60_000` ms in browser, `Infinity` in non-browser)
|
|
44
|
+
* - Default store options can be configured in `StoreRegistry` constructor.
|
|
45
|
+
* - Store options are only applied when the store is loaded. Subsequent calls with different options will not affect the store if it's already loaded and cached in the registry.
|
|
54
46
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* const { store } = useStore({ store: myExternalStore })
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @throws Error if called outside of `<LiveStoreProvider>` or before the store is running
|
|
47
|
+
* @typeParam TSchema - The schema type for the store
|
|
48
|
+
* @returns The loaded store instance augmented with React hooks
|
|
49
|
+
* @throws unknown - store loading error or if called outside `<StoreRegistryProvider>`
|
|
62
50
|
*/
|
|
63
51
|
export const useStore = (options) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
const storeRegistry = useStoreRegistry();
|
|
53
|
+
// Called on every render (intentionally not memoized). For already-loaded stores this returns
|
|
54
|
+
// the Store synchronously, so React.use() is skipped entirely. Caching the initial Promise via
|
|
55
|
+
// useMemo would cause React.use() to be called with a resolved Promise on subsequent renders,
|
|
56
|
+
// which blocks React transitions from committing.
|
|
57
|
+
const storeOrPromise = storeRegistry.getOrLoadPromise(options);
|
|
58
|
+
const store = storeOrPromise instanceof Promise ? React.use(storeOrPromise) : storeOrPromise;
|
|
59
|
+
// NOTE: retain() must be declared AFTER the React.use() call above. When React.use() suspends
|
|
60
|
+
// the component, any hooks declared before it get committed while hooks after the suspension
|
|
61
|
+
// point (including those in the caller) don't. On re-render when the store resolves synchronously,
|
|
62
|
+
// those late hooks appear for the first time, causing a hook-order violation in strict mode.
|
|
63
|
+
// By placing useEffect after React.use(), no effect hooks are committed during suspension,
|
|
64
|
+
// so React treats all effects as fresh mounts on the first successful render.
|
|
65
|
+
//
|
|
66
|
+
// retain() is called in useEffect (after render), while getOrLoadPromise() is called during
|
|
67
|
+
// render. This creates a timing gap where with very short unusedCacheTime values (e.g., 0),
|
|
68
|
+
// the store could theoretically be disposed before the effect fires. In practice, this is not
|
|
69
|
+
// an issue with the default 60s cache time, but it becomes an issue when `unusedCacheTime` is
|
|
70
|
+
// configured to values less than ~100ms.
|
|
71
|
+
// See https://github.com/livestorejs/livestore/issues/916
|
|
72
|
+
React.useEffect(() => storeRegistry.retain(options), [storeRegistry, options]);
|
|
73
|
+
return withReactApi(store);
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Augments a Store instance with React-specific methods (`useQuery`, `useClientDocument`).
|
|
77
|
+
*
|
|
78
|
+
* This is called automatically by `useStore()`. You typically don't need to call it
|
|
79
|
+
* directly unless you're building custom integrations.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export const withReactApi = (store) => {
|
|
84
|
+
// @ts-expect-error TODO properly implement this
|
|
85
|
+
store.useQuery = (queryable) => useQuery(queryable, { store });
|
|
86
|
+
// @ts-expect-error TODO properly implement this
|
|
87
|
+
store.useClientDocument = (table, idOrOptions, options) => useClientDocument(table, idOrOptions, options, { store });
|
|
88
|
+
// @ts-expect-error TODO properly implement this
|
|
89
|
+
store.useSyncStatus = () => useSyncStatus({ store });
|
|
90
|
+
return store;
|
|
76
91
|
};
|
|
77
92
|
//# sourceMappingURL=useStore.js.map
|
package/dist/useStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.js","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useStore.js","sourceRoot":"","sources":["../src/useStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA4B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAKtB,OAAoE,EAC/B,EAAE;IACvC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,8FAA8F;IAC9F,+FAA+F;IAC/F,8FAA8F;IAC9F,kDAAkD;IAClD,MAAM,cAAc,GAAG,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAE9D,MAAM,KAAK,GAAG,cAAc,YAAY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAA;IAE5F,8FAA8F;IAC9F,6FAA6F;IAC7F,mGAAmG;IACnG,6FAA6F;IAC7F,2FAA2F;IAC3F,8EAA8E;IAC9E,EAAE;IACF,4FAA4F;IAC5F,4FAA4F;IAC5F,8FAA8F;IAC9F,8FAA8F;IAC9F,yCAAyC;IACzC,0DAA0D;IAC1D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAA;IAE9E,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA;AAkBD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAA+B,EACM,EAAE;IACvC,gDAAgD;IAChD,KAAK,CAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAE9D,gDAAgD;IAChD,KAAK,CAAC,iBAAiB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAEpH,gDAAgD;IAChD,KAAK,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IAEpD,OAAO,KAA4C,CAAA;AACrD,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.test.d.ts","sourceRoot":"","sources":["../src/useStore.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { makeInMemoryAdapter } from '@livestore/adapter-web';
|
|
3
|
-
import { StoreInternalsSymbol } from '@livestore/livestore';
|
|
3
|
+
import { StoreInternalsSymbol, StoreRegistry, storeOptions, } from '@livestore/livestore';
|
|
4
4
|
import { shouldNeverHappen } from '@livestore/utils';
|
|
5
|
-
import { act, render, renderHook, waitFor } from '@testing-library/react';
|
|
5
|
+
import { act, fireEvent, render, renderHook, waitFor } from '@testing-library/react';
|
|
6
6
|
import * as React from 'react';
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
8
|
-
import { schema } from "
|
|
9
|
-
import { StoreRegistry } from "./StoreRegistry.js";
|
|
7
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
8
|
+
import { schema } from "./__tests__/fixture.js";
|
|
10
9
|
import { StoreRegistryProvider } from "./StoreRegistryContext.js";
|
|
11
|
-
import { storeOptions } from "./storeOptions.js";
|
|
12
10
|
import { useStore } from "./useStore.js";
|
|
13
11
|
describe('experimental useStore', () => {
|
|
14
12
|
it('should return the same promise instance for concurrent getOrLoadStore calls', async () => {
|
|
15
|
-
const
|
|
13
|
+
const storeRegistry = new StoreRegistry();
|
|
16
14
|
const options = testStoreOptions();
|
|
17
15
|
// Make two concurrent calls during loading
|
|
18
|
-
const firstStore =
|
|
19
|
-
const secondStore =
|
|
16
|
+
const firstStore = storeRegistry.getOrLoadPromise(options);
|
|
17
|
+
const secondStore = storeRegistry.getOrLoadPromise(options);
|
|
20
18
|
// Both should be promises (store is loading)
|
|
21
19
|
expect(firstStore).toBeInstanceOf(Promise);
|
|
22
20
|
expect(secondStore).toBeInstanceOf(Promise);
|
|
@@ -28,11 +26,11 @@ describe('experimental useStore', () => {
|
|
|
28
26
|
await cleanupAfterUnmount(() => { });
|
|
29
27
|
});
|
|
30
28
|
it('works with Suspense boundary', async () => {
|
|
31
|
-
const
|
|
29
|
+
const storeRegistry = new StoreRegistry();
|
|
32
30
|
const options = testStoreOptions();
|
|
33
31
|
let view;
|
|
34
32
|
await act(async () => {
|
|
35
|
-
view = render(_jsx(StoreRegistryProvider, { storeRegistry:
|
|
33
|
+
view = render(_jsx(StoreRegistryProvider, { storeRegistry: storeRegistry, children: _jsx(React.Suspense, { fallback: makeSuspenseFallback(), children: _jsx(StoreConsumer, { options: options }) }) }));
|
|
36
34
|
});
|
|
37
35
|
const renderedView = view ?? shouldNeverHappen('render failed');
|
|
38
36
|
// After loading completes, should show the actual content
|
|
@@ -41,9 +39,9 @@ describe('experimental useStore', () => {
|
|
|
41
39
|
await cleanupAfterUnmount(() => renderedView.unmount());
|
|
42
40
|
});
|
|
43
41
|
it('does not re-suspend on subsequent renders when store is already loaded', async () => {
|
|
44
|
-
const
|
|
42
|
+
const storeRegistry = new StoreRegistry();
|
|
45
43
|
const options = testStoreOptions();
|
|
46
|
-
const Wrapper = ({ opts }) => (_jsx(StoreRegistryProvider, { storeRegistry:
|
|
44
|
+
const Wrapper = ({ opts }) => (_jsx(StoreRegistryProvider, { storeRegistry: storeRegistry, children: _jsx(React.Suspense, { fallback: makeSuspenseFallback(), children: _jsx(StoreConsumer, { options: opts }) }) }));
|
|
47
45
|
let view;
|
|
48
46
|
await act(async () => {
|
|
49
47
|
view = render(_jsx(Wrapper, { opts: options }));
|
|
@@ -53,8 +51,9 @@ describe('experimental useStore', () => {
|
|
|
53
51
|
await waitForSuspenseResolved(renderedView);
|
|
54
52
|
expect(renderedView.getByTestId('ready')).toBeDefined();
|
|
55
53
|
// Rerender with new options object (but same storeId)
|
|
54
|
+
const rerenderOptions = cloneStoreOptions(options);
|
|
56
55
|
await act(async () => {
|
|
57
|
-
renderedView.rerender(_jsx(Wrapper, { opts:
|
|
56
|
+
renderedView.rerender(_jsx(Wrapper, { opts: rerenderOptions }));
|
|
58
57
|
});
|
|
59
58
|
// Should not show fallback
|
|
60
59
|
expect(renderedView.queryByTestId('fallback')).toBeNull();
|
|
@@ -62,28 +61,28 @@ describe('experimental useStore', () => {
|
|
|
62
61
|
await cleanupAfterUnmount(() => renderedView.unmount());
|
|
63
62
|
});
|
|
64
63
|
it('throws when store loading fails', async () => {
|
|
65
|
-
const
|
|
64
|
+
const storeRegistry = new StoreRegistry();
|
|
66
65
|
const badOptions = testStoreOptions({
|
|
67
66
|
// @ts-expect-error - intentionally passing invalid adapter to trigger error
|
|
68
67
|
adapter: null,
|
|
69
68
|
});
|
|
70
69
|
// Pre-load the store to cache the error (error happens synchronously)
|
|
71
|
-
expect(() =>
|
|
70
|
+
expect(() => storeRegistry.getOrLoadPromise(badOptions)).toThrow();
|
|
72
71
|
// Now when useStore tries to get it, it should throw synchronously
|
|
73
72
|
expect(() => renderHook(() => useStore(badOptions), {
|
|
74
|
-
wrapper: makeProvider(
|
|
73
|
+
wrapper: makeProvider(storeRegistry),
|
|
75
74
|
})).toThrow();
|
|
76
75
|
});
|
|
77
76
|
it.each([
|
|
78
77
|
{ label: 'non-strict mode', strictMode: false },
|
|
79
78
|
{ label: 'strict mode', strictMode: true },
|
|
80
79
|
])('works in $label', async ({ strictMode }) => {
|
|
81
|
-
const
|
|
80
|
+
const storeRegistry = new StoreRegistry();
|
|
82
81
|
const options = testStoreOptions();
|
|
83
82
|
let hook;
|
|
84
83
|
await act(async () => {
|
|
85
84
|
hook = renderHook(() => useStore(options), {
|
|
86
|
-
wrapper: makeProvider(
|
|
85
|
+
wrapper: makeProvider(storeRegistry, { suspense: true }),
|
|
87
86
|
reactStrictMode: strictMode,
|
|
88
87
|
});
|
|
89
88
|
});
|
|
@@ -94,14 +93,14 @@ describe('experimental useStore', () => {
|
|
|
94
93
|
await cleanupAfterUnmount(unmount);
|
|
95
94
|
});
|
|
96
95
|
it('handles switching between different storeId values', async () => {
|
|
97
|
-
const
|
|
96
|
+
const storeRegistry = new StoreRegistry();
|
|
98
97
|
const optionsA = testStoreOptions({ storeId: 'store-a' });
|
|
99
98
|
const optionsB = testStoreOptions({ storeId: 'store-b' });
|
|
100
99
|
let hook;
|
|
101
100
|
await act(async () => {
|
|
102
101
|
hook = renderHook((opts) => useStore(opts), {
|
|
103
102
|
initialProps: optionsA,
|
|
104
|
-
wrapper: makeProvider(
|
|
103
|
+
wrapper: makeProvider(storeRegistry, { suspense: true }),
|
|
105
104
|
});
|
|
106
105
|
});
|
|
107
106
|
const { result, rerender, unmount } = hook ?? shouldNeverHappen('renderHook failed');
|
|
@@ -123,10 +122,42 @@ describe('experimental useStore', () => {
|
|
|
123
122
|
expect(storeB).not.toBe(storeA);
|
|
124
123
|
await cleanupAfterUnmount(unmount);
|
|
125
124
|
});
|
|
125
|
+
it('does not block useActionState transitions from committing', async () => {
|
|
126
|
+
const storeRegistry = new StoreRegistry();
|
|
127
|
+
const options = testStoreOptions();
|
|
128
|
+
const getOrLoadSpy = vi.spyOn(storeRegistry, 'getOrLoadPromise');
|
|
129
|
+
let view;
|
|
130
|
+
await act(async () => {
|
|
131
|
+
view = render(_jsx(StoreRegistryProvider, { storeRegistry: storeRegistry, children: _jsx(React.Suspense, { fallback: makeSuspenseFallback(), children: _jsx(StoreWithActionState, { options: options }) }) }));
|
|
132
|
+
});
|
|
133
|
+
const renderedView = view ?? shouldNeverHappen('render failed');
|
|
134
|
+
// Wait for store to load
|
|
135
|
+
await waitForSuspenseResolved(renderedView);
|
|
136
|
+
expect(renderedView.getByTestId('state').textContent).toBe('none');
|
|
137
|
+
expect(renderedView.getByTestId('pending').textContent).toBe('false');
|
|
138
|
+
// After store is loaded, clear spy to only track calls during the transition render
|
|
139
|
+
getOrLoadSpy.mockClear();
|
|
140
|
+
// Trigger a useActionState transition
|
|
141
|
+
await act(async () => {
|
|
142
|
+
fireEvent.click(renderedView.getByTestId('submit'));
|
|
143
|
+
});
|
|
144
|
+
// getOrLoadPromise must be called on each render (not cached via useMemo).
|
|
145
|
+
// When the initial Promise is cached, React.use() is called with a resolved Promise
|
|
146
|
+
// on every subsequent render, which blocks React transitions (e.g. useActionState)
|
|
147
|
+
// from ever committing in browser environments.
|
|
148
|
+
expect(getOrLoadSpy).toHaveBeenCalled();
|
|
149
|
+
// The transition should commit: state updates and isPending returns to false
|
|
150
|
+
await waitFor(() => {
|
|
151
|
+
expect(renderedView.getByTestId('state').textContent).toBe('updated');
|
|
152
|
+
expect(renderedView.getByTestId('pending').textContent).toBe('false');
|
|
153
|
+
});
|
|
154
|
+
getOrLoadSpy.mockRestore();
|
|
155
|
+
await cleanupAfterUnmount(() => renderedView.unmount());
|
|
156
|
+
});
|
|
126
157
|
// useStore doesn't handle unusedCacheTime=0 correctly because retain is called in useEffect (after render)
|
|
127
158
|
// See https://github.com/livestorejs/livestore/issues/916
|
|
128
159
|
it.skip('should load store with unusedCacheTime set to 0', async () => {
|
|
129
|
-
const
|
|
160
|
+
const storeRegistry = new StoreRegistry({ defaultOptions: { unusedCacheTime: 0 } });
|
|
130
161
|
const options = testStoreOptions({ unusedCacheTime: 0 });
|
|
131
162
|
const StoreConsumerWithVerification = ({ opts }) => {
|
|
132
163
|
const store = useStore(opts);
|
|
@@ -136,7 +167,7 @@ describe('experimental useStore', () => {
|
|
|
136
167
|
};
|
|
137
168
|
let view;
|
|
138
169
|
await act(async () => {
|
|
139
|
-
view = render(_jsx(StoreRegistryProvider, { storeRegistry:
|
|
170
|
+
view = render(_jsx(StoreRegistryProvider, { storeRegistry: storeRegistry, children: _jsx(React.Suspense, { fallback: makeSuspenseFallback(), children: _jsx(StoreConsumerWithVerification, { opts: options }) }) }));
|
|
140
171
|
});
|
|
141
172
|
const renderedView = view ?? shouldNeverHappen('render failed');
|
|
142
173
|
await waitForSuspenseResolved(renderedView);
|
|
@@ -154,9 +185,21 @@ const StoreConsumer = ({ options }) => {
|
|
|
154
185
|
useStore(options);
|
|
155
186
|
return _jsx("div", { "data-testid": "ready" });
|
|
156
187
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
188
|
+
/** Component that combines useStore with useActionState to test transition compatibility. */
|
|
189
|
+
const StoreWithActionState = ({ options }) => {
|
|
190
|
+
useStore(options);
|
|
191
|
+
const [state, dispatch, isPending] = React.useActionState((_prev, value) => value, undefined);
|
|
192
|
+
return (_jsxs("div", { children: [_jsx("button", { "data-testid": "submit",
|
|
193
|
+
// eslint-disable-next-line react-perf/jsx-no-new-function-as-prop -- test component
|
|
194
|
+
onClick: () => React.startTransition(() => dispatch('updated')), children: "Submit" }), _jsx("div", { "data-testid": "state", children: state ?? 'none' }), _jsx("div", { "data-testid": "pending", children: String(isPending) })] }));
|
|
195
|
+
};
|
|
196
|
+
const makeSuspenseFallback = () => React.createElement('div', { 'data-testid': 'fallback' });
|
|
197
|
+
const cloneStoreOptions = (options) => {
|
|
198
|
+
return { ...options };
|
|
199
|
+
};
|
|
200
|
+
const makeProvider = (storeRegistry, { suspense = false } = {}) => ({ children }) => {
|
|
201
|
+
let content = _jsx(StoreRegistryProvider, { storeRegistry: storeRegistry, children: children });
|
|
202
|
+
if (suspense !== undefined) {
|
|
160
203
|
content = _jsx(React.Suspense, { fallback: null, children: content });
|
|
161
204
|
}
|
|
162
205
|
return content;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.test.js","sourceRoot":"","sources":["../src/useStore.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAGL,oBAAoB,EACpB,aAAa,EACb,YAAY,GACb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,GAAG,EAA4C,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAC9H,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAyB,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA4B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,6EAA6E,EAAE,KAAK,IAAI,EAAE;QAC3F,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAA;QAElC,2CAA2C;QAC3C,MAAM,UAAU,GAAG,aAAa,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B,CAAC,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,CAAA;IAC1E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Store, SyncStatus } from '@livestore/livestore';
|
|
2
|
+
/**
|
|
3
|
+
* React hook that subscribes to sync status changes.
|
|
4
|
+
*
|
|
5
|
+
* Returns the current synchronization status between the client session and
|
|
6
|
+
* the leader thread. The component re-renders whenever the sync status changes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function SyncIndicator() {
|
|
11
|
+
* const status = store.useSyncStatus()
|
|
12
|
+
* return <span>{status.isSynced ? '✓ Synced' : `Syncing (${status.pendingCount} pending)...`}</span>
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param options - Options containing the store instance
|
|
17
|
+
* @returns The current sync status
|
|
18
|
+
*/
|
|
19
|
+
export declare const useSyncStatus: (options: {
|
|
20
|
+
store: Store<any>;
|
|
21
|
+
}) => SyncStatus;
|
|
22
|
+
//# sourceMappingURL=useSyncStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncStatus.d.ts","sourceRoot":"","sources":["../src/useSyncStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS;IAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CAAE,KAAG,UAY9D,CAAA"}
|