@livestore/react 0.4.0-dev.12 → 0.4.0-dev.14
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/__tests__/fixture.d.ts +3 -2
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +3 -2
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/mod.d.ts +1 -0
- package/dist/experimental/mod.d.ts.map +1 -1
- package/dist/experimental/mod.js +1 -0
- package/dist/experimental/mod.js.map +1 -1
- package/dist/experimental/multi-store/StoreRegistry.d.ts +75 -0
- package/dist/experimental/multi-store/StoreRegistry.d.ts.map +1 -0
- package/dist/experimental/multi-store/StoreRegistry.js +286 -0
- package/dist/experimental/multi-store/StoreRegistry.js.map +1 -0
- package/dist/experimental/multi-store/StoreRegistryContext.d.ts +10 -0
- package/dist/experimental/multi-store/StoreRegistryContext.d.ts.map +1 -0
- package/dist/experimental/multi-store/StoreRegistryContext.js +15 -0
- package/dist/experimental/multi-store/StoreRegistryContext.js.map +1 -0
- package/dist/experimental/multi-store/mod.d.ts +6 -0
- package/dist/experimental/multi-store/mod.d.ts.map +1 -0
- package/dist/experimental/multi-store/mod.js +6 -0
- package/dist/experimental/multi-store/mod.js.map +1 -0
- package/dist/experimental/multi-store/storeOptions.d.ts +4 -0
- package/dist/experimental/multi-store/storeOptions.d.ts.map +1 -0
- package/dist/experimental/multi-store/storeOptions.js +4 -0
- package/dist/experimental/multi-store/storeOptions.js.map +1 -0
- package/dist/experimental/multi-store/types.d.ts +44 -0
- package/dist/experimental/multi-store/types.d.ts.map +1 -0
- package/dist/experimental/multi-store/types.js +2 -0
- package/dist/experimental/multi-store/types.js.map +1 -0
- package/dist/experimental/multi-store/useStore.d.ts +11 -0
- package/dist/experimental/multi-store/useStore.d.ts.map +1 -0
- package/dist/experimental/multi-store/useStore.js +21 -0
- package/dist/experimental/multi-store/useStore.js.map +1 -0
- package/dist/useQuery.d.ts +28 -6
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +54 -7
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +24 -0
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useStore.d.ts +2 -1
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +1 -1
- package/dist/useStore.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/fixture.tsx +7 -16
- package/src/experimental/mod.ts +1 -0
- package/src/experimental/multi-store/StoreRegistry.ts +356 -0
- package/src/experimental/multi-store/StoreRegistryContext.tsx +23 -0
- package/src/experimental/multi-store/mod.ts +5 -0
- package/src/experimental/multi-store/storeOptions.ts +8 -0
- package/src/experimental/multi-store/types.ts +55 -0
- package/src/experimental/multi-store/useStore.ts +39 -0
- package/src/useQuery.test.tsx +45 -0
- package/src/useQuery.ts +84 -16
- package/src/useStore.ts +4 -3
|
@@ -276,11 +276,12 @@ export declare const schema: import("@livestore/livestore").FromInputSchema.Deri
|
|
|
276
276
|
}>;
|
|
277
277
|
};
|
|
278
278
|
}>;
|
|
279
|
-
export
|
|
279
|
+
export type MakeTodoMvcReactOptions = {
|
|
280
280
|
otelTracer?: otel.Tracer | undefined;
|
|
281
281
|
otelContext?: otel.Context | undefined;
|
|
282
282
|
strictMode?: boolean | undefined;
|
|
283
|
-
}
|
|
283
|
+
};
|
|
284
|
+
export declare const makeTodoMvcReact: (opts?: MakeTodoMvcReactOptions) => Effect.Effect<{
|
|
284
285
|
wrapper: ({ children }: any) => React.JSX.Element;
|
|
285
286
|
store: Store<LiveStoreSchema<SqliteDsl.DbSchema, State.SQLite.EventDefRecord>, {}> & LiveStoreReact.ReactApi;
|
|
286
287
|
renderCount: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,eAAe,EAAE,MAA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,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,uBAAuB,KAAK,MAAM,CAAC,MAAM,CAC9E;IACE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;IACjD,KAAK,EAAE,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAA;IAC5G,WAAW,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CACvD,EACD,eAAe,EACf,KAAK,CAAC,KAAK,CA+C+F,CAAA"}
|
|
@@ -70,7 +70,8 @@ const materializers = State.SQLite.materializers(events, {
|
|
|
70
70
|
export const tables = { todos, app, userInfo, AppRouterSchema, kv };
|
|
71
71
|
const state = State.SQLite.makeState({ tables, materializers });
|
|
72
72
|
export const schema = makeSchema({ state, events });
|
|
73
|
-
export const makeTodoMvcReact = (
|
|
73
|
+
export const makeTodoMvcReact = (opts = {}) => Effect.gen(function* () {
|
|
74
|
+
const { strictMode } = opts;
|
|
74
75
|
const makeRenderCount = () => {
|
|
75
76
|
let val = 0;
|
|
76
77
|
const inc = () => {
|
|
@@ -99,5 +100,5 @@ export const makeTodoMvcReact = ({ otelTracer, otelContext, strictMode, } = {})
|
|
|
99
100
|
const wrapper = ({ children }) => (_jsx(MaybeStrictMode, { children: _jsx(LiveStoreReact.LiveStoreContext.Provider, { value: storeContext, children: children }) }));
|
|
100
101
|
const renderCount = makeRenderCount();
|
|
101
102
|
return { wrapper, store: storeWithReactApi, renderCount };
|
|
102
|
-
}).pipe(provideOtel(omitUndefineds({ parentSpanContext: otelContext, otelTracer })));
|
|
103
|
+
}).pipe(provideOtel(omitUndefineds({ parentSpanContext: opts.otelContext, otelTracer: opts.otelTracer })));
|
|
103
104
|
//# sourceMappingURL=fixture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../src/__tests__/fixture.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAc,MAAM,yBAAyB,CAAA;AAEpE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,cAAc,MAAM,WAAW,CAAA;AAe3C,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;IAC/B,IAAI,EAAE,OAAO;IACb,OAAO,EAAE;QACP,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC3C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACzD,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;KACrE;CACF,CAAC,CAAA;AAEF,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;IAC7B,IAAI,EAAE,KAAK;IACX,OAAO,EAAE;QACP,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC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,GAAG,CAAC,EAAE,QAAQ,EAAO,EAAE,EAAE,CAAC,CACrC,KAAC,eAAe,cACd,KAAC,cAAc,CAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC1D,QAAQ,GACgC,GAC3B,CACnB,CAAA;IAED,MAAM,WAAW,GAAG,eAAe,EAAE,CAAA;IAErC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAA;AAC3D,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACxE,cAAc,sBAAsB,CAAA"}
|
package/dist/experimental/mod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA2B,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/experimental/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA2B,CAAA;AACxE,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 inactive stores remain in memory.
|
|
7
|
+
* When a store becomes inactive, it will be garbage collected
|
|
8
|
+
* after this duration.
|
|
9
|
+
*
|
|
10
|
+
* Stores transition to the inactive 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 garbage collection
|
|
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
|
+
gcTime?: number;
|
|
22
|
+
};
|
|
23
|
+
type StoreRegistryConfig = {
|
|
24
|
+
defaultOptions?: DefaultStoreOptions;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Store Registry coordinating cache, GC, and Suspense reads.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare class StoreRegistry {
|
|
32
|
+
#private;
|
|
33
|
+
constructor({ defaultOptions }?: StoreRegistryConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a store instance for imperative code paths.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam TSchema - Schema associated with the requested store.
|
|
38
|
+
* @returns A promise that resolves with the ready store or rejects with the loading error.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* - If the store is already cached, the returned promise resolves immediately with that instance.
|
|
42
|
+
* - Concurrent callers share the same in-flight request to avoid duplicate store creation.
|
|
43
|
+
*/
|
|
44
|
+
load: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Promise<Store<TSchema>>;
|
|
45
|
+
/**
|
|
46
|
+
* Reads a store, returning it directly if loaded or a promise if loading.
|
|
47
|
+
* Designed to work with React.use() for Suspense integration.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam TSchema - The schema of the store to load
|
|
50
|
+
* @returns The loaded store if available, or a Promise that resolves to the store if loading
|
|
51
|
+
* @throws unknown loading error to integrate with React Error Boundaries
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* - When the store is already loaded, returns the store instance directly (not wrapped in a Promise)
|
|
55
|
+
* - When loading, returns a stable Promise reference that can be used with React.use()
|
|
56
|
+
* - This prevents re-suspension on subsequent renders when the store is already loaded
|
|
57
|
+
* - If the initial render that triggered the fetch never commits, we still schedule GC on settle.
|
|
58
|
+
*/
|
|
59
|
+
read: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Store<TSchema> | Promise<Store<TSchema>>;
|
|
60
|
+
/**
|
|
61
|
+
* Warms the cache for a store without mounting a subscriber.
|
|
62
|
+
*
|
|
63
|
+
* @typeParam TSchema - The schema of the store to preload
|
|
64
|
+
* @returns A promise that resolves when the loading is complete (success or failure)
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* - We don't return the store or throw as this is a fire-and-forget operation.
|
|
68
|
+
* - If the entry remains unused after preload resolves/rejects, it is scheduled for GC.
|
|
69
|
+
*/
|
|
70
|
+
preload: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Promise<void>;
|
|
71
|
+
subscribe: <TSchema extends LiveStoreSchema>(storeId: StoreId, listener: () => void) => Unsubscribe;
|
|
72
|
+
getVersion: <TSchema extends LiveStoreSchema>(storeId: StoreId) => number;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=StoreRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAEvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AA+I7D,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,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC,CAAA;AAED;;;;GAIG;AACH,qBAAa,aAAa;;gBAKZ,EAAE,cAAmB,EAAE,GAAE,mBAAwB;IAgB7D;;;;;;;;;OASG;IACH,IAAI,GAAU,OAAO,SAAS,eAAe,EAAE,SAAS,kBAAkB,CAAC,OAAO,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAiC5G;IAED;;;;;;;;;;;;;OAaG;IACH,IAAI,GAAI,OAAO,SAAS,eAAe,EACrC,SAAS,kBAAkB,CAAC,OAAO,CAAC,KACnC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAiC1C;IAED;;;;;;;;;OASG;IACH,OAAO,GAAU,OAAO,SAAS,eAAe,EAAE,SAAS,kBAAkB,CAAC,OAAO,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC,CAErG;IAED,SAAS,GAAI,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO,EAAE,UAAU,MAAM,IAAI,KAAG,WAAW,CAcjG;IAED,UAAU,GAAI,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO,KAAG,MAAM,CAGvE;CAyBF"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { createStorePromise } from '@livestore/livestore';
|
|
2
|
+
import { noop } from '@livestore/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Minimal cache entry that tracks store, error, and in-flight promise along with subscribers.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam TSchema - The schema for this entry's store.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
class StoreEntry {
|
|
10
|
+
/**
|
|
11
|
+
* The resolved store.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* A value of `undefined` indicates "not loaded yet".
|
|
15
|
+
*/
|
|
16
|
+
store = undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The most recent error encountered for this entry, if any.
|
|
19
|
+
*/
|
|
20
|
+
error = undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The in-flight promise for loading the store, or `undefined` if not yet loading or already resolved.
|
|
23
|
+
*/
|
|
24
|
+
promise = undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Set of subscriber callbacks to notify on state changes.
|
|
27
|
+
*/
|
|
28
|
+
#subscribers = new Set();
|
|
29
|
+
/**
|
|
30
|
+
* Monotonic counter that increments on every notify.
|
|
31
|
+
*/
|
|
32
|
+
version = 0;
|
|
33
|
+
/**
|
|
34
|
+
* The number of active subscribers for this entry.
|
|
35
|
+
*/
|
|
36
|
+
get subscriberCount() {
|
|
37
|
+
return this.#subscribers.size;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Subscribes to this entry's updates.
|
|
41
|
+
*
|
|
42
|
+
* @param listener - Callback invoked when the entry changes
|
|
43
|
+
* @returns Unsubscribe function
|
|
44
|
+
*/
|
|
45
|
+
subscribe = (listener) => {
|
|
46
|
+
this.#subscribers.add(listener);
|
|
47
|
+
return () => {
|
|
48
|
+
this.#subscribers.delete(listener);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Notifies all subscribers and increments the version counter.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* This should be called after any meaningful state change.
|
|
56
|
+
*/
|
|
57
|
+
notify = () => {
|
|
58
|
+
this.version++;
|
|
59
|
+
for (const sub of this.#subscribers) {
|
|
60
|
+
try {
|
|
61
|
+
sub();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Swallow to protect other listeners
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
setStore = (store) => {
|
|
69
|
+
this.store = store;
|
|
70
|
+
this.error = undefined;
|
|
71
|
+
this.promise = undefined;
|
|
72
|
+
this.notify();
|
|
73
|
+
};
|
|
74
|
+
setError = (error) => {
|
|
75
|
+
this.error = error;
|
|
76
|
+
this.promise = undefined;
|
|
77
|
+
this.notify();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* In-memory map of {@link StoreEntry} instances keyed by {@link StoreId}.
|
|
82
|
+
*
|
|
83
|
+
* @privateRemarks
|
|
84
|
+
* The cache is intentionally small; eviction and GC timers are coordinated by the client.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
class StoreCache {
|
|
89
|
+
#entries = new Map();
|
|
90
|
+
get = (storeId) => {
|
|
91
|
+
return this.#entries.get(storeId);
|
|
92
|
+
};
|
|
93
|
+
getOrCreate = (storeId) => {
|
|
94
|
+
let entry = this.#entries.get(storeId);
|
|
95
|
+
if (!entry) {
|
|
96
|
+
entry = new StoreEntry();
|
|
97
|
+
this.#entries.set(storeId, entry);
|
|
98
|
+
}
|
|
99
|
+
return entry;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Removes an entry from the cache and notifies its subscribers.
|
|
103
|
+
*
|
|
104
|
+
* @param storeId - The ID of the store to remove
|
|
105
|
+
* @remarks
|
|
106
|
+
* Notifying subscribers prompts consumers to re-render and re-read as needed.
|
|
107
|
+
*/
|
|
108
|
+
remove = (storeId) => {
|
|
109
|
+
const entry = this.#entries.get(storeId);
|
|
110
|
+
if (!entry)
|
|
111
|
+
return;
|
|
112
|
+
this.#entries.delete(storeId);
|
|
113
|
+
// Notify any subscribers of the removal to force re-render;
|
|
114
|
+
// components will resubscribe to a new entry and re-read.
|
|
115
|
+
try {
|
|
116
|
+
entry.notify();
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Best-effort notify; swallowing to avoid crashing removal flows.
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
clear = () => {
|
|
123
|
+
for (const storeId of Array.from(this.#entries.keys())) {
|
|
124
|
+
this.remove(storeId);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const DEFAULT_GC_TIME = typeof window === 'undefined' ? Number.POSITIVE_INFINITY : 60_000;
|
|
129
|
+
/**
|
|
130
|
+
* Store Registry coordinating cache, GC, and Suspense reads.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export class StoreRegistry {
|
|
135
|
+
#cache = new StoreCache();
|
|
136
|
+
#gcTimeouts = new Map();
|
|
137
|
+
#defaultOptions;
|
|
138
|
+
constructor({ defaultOptions = {} } = {}) {
|
|
139
|
+
this.#defaultOptions = defaultOptions;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Ensures a store entry exists in the cache.
|
|
143
|
+
*
|
|
144
|
+
* @param storeId - The ID of the store
|
|
145
|
+
* @returns The existing or newly created store entry
|
|
146
|
+
*
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
ensureStoreEntry = (storeId) => {
|
|
150
|
+
return this.#cache.getOrCreate(storeId);
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Resolves a store instance for imperative code paths.
|
|
154
|
+
*
|
|
155
|
+
* @typeParam TSchema - Schema associated with the requested store.
|
|
156
|
+
* @returns A promise that resolves with the ready store or rejects with the loading error.
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* - If the store is already cached, the returned promise resolves immediately with that instance.
|
|
160
|
+
* - Concurrent callers share the same in-flight request to avoid duplicate store creation.
|
|
161
|
+
*/
|
|
162
|
+
load = async (options) => {
|
|
163
|
+
const optionsWithDefaults = this.#applyDefaultOptions(options);
|
|
164
|
+
const entry = this.ensureStoreEntry(optionsWithDefaults.storeId);
|
|
165
|
+
// If already loaded, return it
|
|
166
|
+
if (entry.store)
|
|
167
|
+
return entry.store;
|
|
168
|
+
// If a load is already in flight, return its promise
|
|
169
|
+
if (entry.promise)
|
|
170
|
+
return entry.promise;
|
|
171
|
+
// If a previous error exists, throw it
|
|
172
|
+
if (entry.error !== undefined)
|
|
173
|
+
throw entry.error;
|
|
174
|
+
// Load store if none is in flight
|
|
175
|
+
entry.promise = createStorePromise(optionsWithDefaults)
|
|
176
|
+
.then((store) => {
|
|
177
|
+
entry.setStore(store);
|
|
178
|
+
// If no one subscribed (e.g., initial render aborted), schedule GC.
|
|
179
|
+
if (entry.subscriberCount === 0)
|
|
180
|
+
this.#scheduleGC(optionsWithDefaults.storeId);
|
|
181
|
+
return store;
|
|
182
|
+
})
|
|
183
|
+
.catch((error) => {
|
|
184
|
+
entry.setError(error);
|
|
185
|
+
// Likewise, ensure unused entries are eventually collected.
|
|
186
|
+
if (entry.subscriberCount === 0)
|
|
187
|
+
this.#scheduleGC(optionsWithDefaults.storeId);
|
|
188
|
+
throw error;
|
|
189
|
+
});
|
|
190
|
+
return entry.promise;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Reads a store, returning it directly if loaded or a promise if loading.
|
|
194
|
+
* Designed to work with React.use() for Suspense integration.
|
|
195
|
+
*
|
|
196
|
+
* @typeParam TSchema - The schema of the store to load
|
|
197
|
+
* @returns The loaded store if available, or a Promise that resolves to the store if loading
|
|
198
|
+
* @throws unknown loading error to integrate with React Error Boundaries
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* - When the store is already loaded, returns the store instance directly (not wrapped in a Promise)
|
|
202
|
+
* - When loading, returns a stable Promise reference that can be used with React.use()
|
|
203
|
+
* - This prevents re-suspension on subsequent renders when the store is already loaded
|
|
204
|
+
* - If the initial render that triggered the fetch never commits, we still schedule GC on settle.
|
|
205
|
+
*/
|
|
206
|
+
read = (options) => {
|
|
207
|
+
const optionsWithDefaults = this.#applyDefaultOptions(options);
|
|
208
|
+
const entry = this.ensureStoreEntry(optionsWithDefaults.storeId);
|
|
209
|
+
// If already loaded, return it directly (not wrapped in Promise)
|
|
210
|
+
if (entry.store)
|
|
211
|
+
return entry.store;
|
|
212
|
+
// If a previous error exists, throw it
|
|
213
|
+
if (entry.error !== undefined)
|
|
214
|
+
throw entry.error;
|
|
215
|
+
// If a load is already in flight, return the existing promise
|
|
216
|
+
if (entry.promise)
|
|
217
|
+
return entry.promise;
|
|
218
|
+
// Load store if none is in flight
|
|
219
|
+
entry.promise = createStorePromise(optionsWithDefaults)
|
|
220
|
+
.then((store) => {
|
|
221
|
+
entry.setStore(store);
|
|
222
|
+
// If no one subscribed (e.g., initial render aborted), schedule GC.
|
|
223
|
+
if (entry.subscriberCount === 0)
|
|
224
|
+
this.#scheduleGC(optionsWithDefaults.storeId);
|
|
225
|
+
return store;
|
|
226
|
+
})
|
|
227
|
+
.catch((error) => {
|
|
228
|
+
entry.setError(error);
|
|
229
|
+
// Likewise, ensure unused entries are eventually collected.
|
|
230
|
+
if (entry.subscriberCount === 0)
|
|
231
|
+
this.#scheduleGC(optionsWithDefaults.storeId);
|
|
232
|
+
throw error;
|
|
233
|
+
});
|
|
234
|
+
return entry.promise;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Warms the cache for a store without mounting a subscriber.
|
|
238
|
+
*
|
|
239
|
+
* @typeParam TSchema - The schema of the store to preload
|
|
240
|
+
* @returns A promise that resolves when the loading is complete (success or failure)
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* - We don't return the store or throw as this is a fire-and-forget operation.
|
|
244
|
+
* - If the entry remains unused after preload resolves/rejects, it is scheduled for GC.
|
|
245
|
+
*/
|
|
246
|
+
preload = async (options) => {
|
|
247
|
+
return this.load(options).then(noop).catch(noop);
|
|
248
|
+
};
|
|
249
|
+
subscribe = (storeId, listener) => {
|
|
250
|
+
const entry = this.ensureStoreEntry(storeId);
|
|
251
|
+
// Active subscriber: cancel any scheduled GC
|
|
252
|
+
this.#cancelGC(storeId);
|
|
253
|
+
const unsubscribe = entry.subscribe(listener);
|
|
254
|
+
return () => {
|
|
255
|
+
unsubscribe();
|
|
256
|
+
// If no more subscribers remain, schedule GC
|
|
257
|
+
if (entry.subscriberCount === 0) {
|
|
258
|
+
this.#scheduleGC(storeId);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
getVersion = (storeId) => {
|
|
263
|
+
const entry = this.ensureStoreEntry(storeId);
|
|
264
|
+
return entry.version;
|
|
265
|
+
};
|
|
266
|
+
#applyDefaultOptions = (options) => ({
|
|
267
|
+
...this.#defaultOptions,
|
|
268
|
+
...options,
|
|
269
|
+
});
|
|
270
|
+
#scheduleGC = (id) => {
|
|
271
|
+
this.#cancelGC(id);
|
|
272
|
+
const timer = setTimeout(() => {
|
|
273
|
+
this.#gcTimeouts.delete(id);
|
|
274
|
+
this.#cache.remove(id);
|
|
275
|
+
}, DEFAULT_GC_TIME);
|
|
276
|
+
this.#gcTimeouts.set(id, timer);
|
|
277
|
+
};
|
|
278
|
+
#cancelGC = (id) => {
|
|
279
|
+
const t = this.#gcTimeouts.get(id);
|
|
280
|
+
if (t) {
|
|
281
|
+
clearTimeout(t);
|
|
282
|
+
this.#gcTimeouts.delete(id);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=StoreRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreRegistry.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAgC,MAAM,sBAAsB,CAAA;AACvF,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvC;;;;;GAKG;AACH,MAAM,UAAU;IACd;;;;;OAKG;IACH,KAAK,GAA+B,SAAS,CAAA;IAE7C;;OAEG;IACH,KAAK,GAAY,SAAS,CAAA;IAE1B;;OAEG;IACH,OAAO,GAAwC,SAAS,CAAA;IAExD;;OAEG;IACH,YAAY,GAAG,IAAI,GAAG,EAAc,CAAA;IAEpC;;OAEG;IACH,OAAO,GAAG,CAAC,CAAA;IAEX;;OAEG;IACH,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAA;IAC/B,CAAC;IAED;;;;;OAKG;IACH,SAAS,GAAG,CAAC,QAAoB,EAAe,EAAE;QAChD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC/B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACpC,CAAC,CAAA;IACH,CAAC,CAAA;IAED;;;;;OAKG;IACH,MAAM,GAAG,GAAS,EAAE;QAClB,IAAI,CAAC,OAAO,EAAE,CAAA;QACd,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,IAAI,CAAC;gBACH,GAAG,EAAE,CAAA;YACP,CAAC;YAAC,MAAM,CAAC;gBACP,qCAAqC;YACvC,CAAC;QACH,CAAC;IACH,CAAC,CAAA;IAED,QAAQ,GAAG,CAAC,KAAqB,EAAQ,EAAE;QACzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,C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OAAgB,EAAU,EAAE;QACzE,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAU,OAAO,CAAC,CAAA;QACrD,OAAO,KAAK,CAAC,OAAO,CAAA;IACtB,CAAC,CAAA;IAED,oBAAoB,GAAG,CACrB,OAAoC,EACP,EAAE,CAAC,CAAC;QACjC,GAAG,IAAI,CAAC,eAAe;QACvB,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,WAAW,GAAG,CAAC,EAAW,EAAQ,EAAE;QAClC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACxB,CAAC,EAAE,eAAe,CAAC,CAAA;QACnB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;IACjC,CAAC,CAAA;IAED,SAAS,GAAG,CAAC,EAAW,EAAQ,EAAE;QAChC,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAClC,IAAI,CAAC,EAAE,CAAC;YACN,YAAY,CAAC,CAAC,CAAC,CAAA;YACf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC,CAAA;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { StoreRegistry } from './StoreRegistry.js';
|
|
3
|
+
export declare const StoreRegistryContext: React.Context<StoreRegistry | undefined>;
|
|
4
|
+
export type StoreRegistryProviderProps = {
|
|
5
|
+
storeRegistry: StoreRegistry;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export declare const StoreRegistryProvider: ({ storeRegistry, children }: StoreRegistryProviderProps) => React.JSX.Element;
|
|
9
|
+
export declare const useStoreRegistry: (override?: StoreRegistry) => StoreRegistry;
|
|
10
|
+
//# sourceMappingURL=StoreRegistryContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreRegistryContext.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistryContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,eAAO,MAAM,oBAAoB,0CAA4D,CAAA;AAE7F,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,6BAA6B,0BAA0B,KAAG,KAAK,CAAC,GAAG,CAAC,OAEzG,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,WAAW,aAAa,kBAQxD,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export const StoreRegistryContext = React.createContext(undefined);
|
|
4
|
+
export const StoreRegistryProvider = ({ storeRegistry, children }) => {
|
|
5
|
+
return _jsx(StoreRegistryContext, { value: storeRegistry, children: children });
|
|
6
|
+
};
|
|
7
|
+
export const useStoreRegistry = (override) => {
|
|
8
|
+
if (override)
|
|
9
|
+
return override;
|
|
10
|
+
const storeRegistry = React.use(StoreRegistryContext);
|
|
11
|
+
if (!storeRegistry)
|
|
12
|
+
throw new Error('useStoreRegistry() must be used within <MultiStoreProvider>');
|
|
13
|
+
return storeRegistry;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=StoreRegistryContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreRegistryContext.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistryContext.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAA4B,SAAS,CAAC,CAAA;AAO7F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,aAAa,EAAE,QAAQ,EAA8B,EAAqB,EAAE;IAClH,OAAO,KAAC,oBAAoB,IAAC,KAAK,EAAE,aAAa,YAAG,QAAQ,GAAwB,CAAA;AACtF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAwB,EAAE,EAAE;IAC3D,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAErD,IAAI,CAAC,aAAa;QAAE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAElG,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/mod.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/mod.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
+
import type { CachedStoreOptions } from './types.ts';
|
|
3
|
+
export declare function storeOptions<TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>): CachedStoreOptions<TSchema>;
|
|
4
|
+
//# sourceMappingURL=storeOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeOptions.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/storeOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD,wBAAgB,YAAY,CAAC,OAAO,SAAS,eAAe,EAC1D,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACnC,kBAAkB,CAAC,OAAO,CAAC,CAE7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeOptions.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/storeOptions.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAC1B,OAAoC;IAEpC,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Adapter } from '@livestore/common';
|
|
2
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
3
|
+
import type { CreateStoreOptions, OtelOptions } from '@livestore/livestore';
|
|
4
|
+
export type StoreId = string;
|
|
5
|
+
/**
|
|
6
|
+
* Minimum information required to create a store
|
|
7
|
+
*/
|
|
8
|
+
export type StoreDescriptor<TSchema extends LiveStoreSchema> = {
|
|
9
|
+
/**
|
|
10
|
+
* Schema describing the data structure.
|
|
11
|
+
*/
|
|
12
|
+
readonly schema: TSchema;
|
|
13
|
+
/**
|
|
14
|
+
* Adapter for persistence and synchronization.
|
|
15
|
+
*/
|
|
16
|
+
readonly adapter: Adapter;
|
|
17
|
+
/**
|
|
18
|
+
* The ID of the store.
|
|
19
|
+
*/
|
|
20
|
+
readonly storeId: StoreId;
|
|
21
|
+
};
|
|
22
|
+
export type CachedStoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}> = StoreDescriptor<TSchema> & Pick<CreateStoreOptions<TSchema, TContext>, 'boot' | 'batchUpdates' | 'disableDevtools' | 'confirmUnsavedChanges' | 'syncPayload' | 'debug'> & {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
otelOptions?: Partial<OtelOptions>;
|
|
25
|
+
/**
|
|
26
|
+
* The time in milliseconds that this store should remain
|
|
27
|
+
* in memory after becoming inactive. When this store becomes
|
|
28
|
+
* inactive, it will be garbage collected after this duration.
|
|
29
|
+
*
|
|
30
|
+
* Stores transition to the inactive state as soon as they have no
|
|
31
|
+
* subscriptions registered, so when all components which use that
|
|
32
|
+
* store have unmounted.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* - When different `gcTime` config are used for the same store, the longest one will be used.
|
|
36
|
+
* - If set to `Infinity`, will disable garbage collection
|
|
37
|
+
* - The maximum allowed time is about {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value | 24 days}
|
|
38
|
+
*
|
|
39
|
+
* @defaultValue `60_000` (60 seconds) or `Infinity` during SSR to avoid
|
|
40
|
+
* disposing stores before server render completes.
|
|
41
|
+
*/
|
|
42
|
+
gcTime?: number;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE3E,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,eAAe,IAAI;IAC7D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,kBAAkB,CAC5B,OAAO,SAAS,eAAe,GAAG,eAAe,CAAC,GAAG,EACrD,QAAQ,GAAG,EAAE,IACX,eAAe,CAAC,OAAO,CAAC,GAC1B,IAAI,CACF,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,EACrC,MAAM,GAAG,cAAc,GAAG,iBAAiB,GAAG,uBAAuB,GAAG,aAAa,GAAG,OAAO,CAChG,GAAG;IACF,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAClC;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
+
import type { Store } from '@livestore/livestore';
|
|
3
|
+
import type { ReactApi } from '../../LiveStoreContext.ts';
|
|
4
|
+
import type { CachedStoreOptions } from './types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Suspense + Error Boundary friendly hook.
|
|
7
|
+
* - Returns data or throws (Promise|Error).
|
|
8
|
+
* - No loading or error states are returned.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useStore: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Store<TSchema> & ReactApi;
|
|
11
|
+
//# sourceMappingURL=useStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/useStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAGzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,eAAe,EACtD,SAAS,kBAAkB,CAAC,OAAO,CAAC,KACnC,KAAK,CAAC,OAAO,CAAC,GAAG,QAuBnB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { withReactApi } from "../../useStore.js";
|
|
3
|
+
import { useStoreRegistry } from "./StoreRegistryContext.js";
|
|
4
|
+
/**
|
|
5
|
+
* Suspense + Error Boundary friendly hook.
|
|
6
|
+
* - Returns data or throws (Promise|Error).
|
|
7
|
+
* - No loading or error states are returned.
|
|
8
|
+
*/
|
|
9
|
+
export const useStore = (options) => {
|
|
10
|
+
const storeRegistry = useStoreRegistry();
|
|
11
|
+
storeRegistry.ensureStoreEntry(options.storeId);
|
|
12
|
+
const subscribe = React.useCallback((onChange) => storeRegistry.subscribe(options.storeId, onChange), [storeRegistry, options.storeId]);
|
|
13
|
+
const getSnapshot = React.useCallback(() => storeRegistry.getVersion(options.storeId), [storeRegistry, options.storeId]);
|
|
14
|
+
React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
15
|
+
const storeOrPromise = storeRegistry.read(options);
|
|
16
|
+
// If read() returns a Promise, use React.use() to suspend
|
|
17
|
+
// If it returns a Store directly, use it immediately
|
|
18
|
+
const loadedStore = storeOrPromise instanceof Promise ? React.use(storeOrPromise) : storeOrPromise;
|
|
19
|
+
return withReactApi(loadedStore);
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=useStore.js.map
|