@livestore/react 0.4.0-dev.21 → 0.4.0-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/StoreRegistryContext.d.ts +56 -0
- package/dist/StoreRegistryContext.d.ts.map +1 -0
- package/dist/StoreRegistryContext.js +61 -0
- package/dist/StoreRegistryContext.js.map +1 -0
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +1 -6
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.d.ts +4 -2
- package/dist/experimental/components/LiveList.d.ts.map +1 -1
- package/dist/experimental/components/LiveList.js +6 -5
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/experimental/mod.d.ts +0 -1
- package/dist/experimental/mod.d.ts.map +1 -1
- package/dist/experimental/mod.js +0 -1
- package/dist/experimental/mod.js.map +1 -1
- package/dist/mod.d.ts +4 -3
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +3 -2
- package/dist/mod.js.map +1 -1
- package/dist/useClientDocument.d.ts.map +1 -1
- package/dist/useClientDocument.js +1 -4
- package/dist/useClientDocument.js.map +1 -1
- package/dist/useQuery.d.ts +1 -1
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +2 -5
- package/dist/useQuery.js.map +1 -1
- package/dist/useStore.d.ts +50 -46
- package/dist/useStore.d.ts.map +1 -1
- package/dist/useStore.js +66 -59
- 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} +20 -22
- package/dist/useStore.test.js.map +1 -0
- package/package.json +7 -7
- package/src/StoreRegistryContext.tsx +69 -0
- package/src/__tests__/fixture.tsx +1 -13
- package/src/experimental/components/LiveList.tsx +13 -4
- package/src/experimental/mod.ts +0 -1
- package/src/mod.ts +4 -3
- package/src/useClientDocument.ts +1 -5
- package/src/useQuery.ts +2 -6
- package/src/{experimental/multi-store/useStore.test.tsx → useStore.test.tsx} +32 -30
- package/src/useStore.ts +94 -66
- 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/src/LiveStoreContext.ts +0 -41
- package/src/LiveStoreProvider.test.tsx +0 -248
- package/src/LiveStoreProvider.tsx +0 -430
- 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/dist/{experimental/multi-store/useStore.test.d.ts → useStore.test.d.ts} +0 -0
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { OtelLiveDummy, UnknownError } from '@livestore/common';
|
|
2
|
-
import { createStore } from '@livestore/livestore';
|
|
3
|
-
import { Cause, Effect, Equal, Exit, Fiber, Hash, Layer, ManagedRuntime, RcMap, Runtime, } from '@livestore/utils/effect';
|
|
4
|
-
/**
|
|
5
|
-
* Default time to keep unused stores in cache.
|
|
6
|
-
*
|
|
7
|
-
* - Browser: 60 seconds (60,000ms)
|
|
8
|
-
* - SSR: Infinity (disables disposal to avoid disposing stores before server render completes)
|
|
9
|
-
*
|
|
10
|
-
* @internal Exported primarily for testing purposes.
|
|
11
|
-
*/
|
|
12
|
-
export const DEFAULT_UNUSED_CACHE_TIME = typeof window === 'undefined' ? Number.POSITIVE_INFINITY : 60_000;
|
|
13
|
-
/**
|
|
14
|
-
* RcMap cache key that uses storeId for equality/hashing but carries full options.
|
|
15
|
-
* This allows RcMap to deduplicate by storeId while the lookup function has access to all options.
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* Only `storeId` is used for equality and hashing. This means if `getOrLoadPromise` is called
|
|
19
|
-
* with different options (e.g., different `adapter`) but the same `storeId`, the cached store
|
|
20
|
-
* from the first call will be returned. This is intentional - a store's identity is determined
|
|
21
|
-
* solely by its `storeId`, and callers should not expect to get different stores by varying
|
|
22
|
-
* other options while keeping the same `storeId`.
|
|
23
|
-
*/
|
|
24
|
-
class StoreCacheKey {
|
|
25
|
-
options;
|
|
26
|
-
constructor(options) {
|
|
27
|
-
this.options = options;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Equality is based solely on `storeId`. Other options in `CachedStoreOptions` are ignored
|
|
31
|
-
* for cache key comparison. The first options used for a given `storeId` determine the
|
|
32
|
-
* store's configuration.
|
|
33
|
-
*/
|
|
34
|
-
[Equal.symbol](that) {
|
|
35
|
-
return that instanceof StoreCacheKey && this.options.storeId === that.options.storeId;
|
|
36
|
-
}
|
|
37
|
-
[Hash.symbol]() {
|
|
38
|
-
return Hash.string(this.options.storeId);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Store Registry coordinating store loading, caching, and retention
|
|
43
|
-
*
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
export class StoreRegistry {
|
|
47
|
-
/**
|
|
48
|
-
* Reference-counted cache mapping storeId to Store instances.
|
|
49
|
-
* Stores are created on first access and disposed after `unusedCacheTime` when all references are released.
|
|
50
|
-
*/
|
|
51
|
-
#rcMap;
|
|
52
|
-
/**
|
|
53
|
-
* Effect runtime providing Scope and OtelTracer for all registry operations.
|
|
54
|
-
* When the runtime's scope closes, all managed stores are automatically shut down.
|
|
55
|
-
*/
|
|
56
|
-
#runtime;
|
|
57
|
-
/**
|
|
58
|
-
* In-flight loading promises keyed by storeId.
|
|
59
|
-
* Ensures concurrent `getOrLoadPromise` calls receive the same Promise reference.
|
|
60
|
-
*/
|
|
61
|
-
#loadingPromises = new Map();
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new StoreRegistry instance.
|
|
64
|
-
*
|
|
65
|
-
* @param params.defaultOptions - Default options applied to all stores managed by this registry when they are loaded.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* const registry = new StoreRegistry({
|
|
70
|
-
* defaultOptions: {
|
|
71
|
-
* batchUpdates,
|
|
72
|
-
* unusedCacheTime: 30_000,
|
|
73
|
-
* }
|
|
74
|
-
* })
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
constructor(params = {}) {
|
|
78
|
-
this.#runtime =
|
|
79
|
-
params.defaultOptions?.runtime ??
|
|
80
|
-
ManagedRuntime.make(Layer.mergeAll(Layer.scope, OtelLiveDummy)).runtimeEffect.pipe(Effect.runSync);
|
|
81
|
-
this.#rcMap = RcMap.make({
|
|
82
|
-
lookup: (key) => Effect.gen(this, function* () {
|
|
83
|
-
const { options } = key;
|
|
84
|
-
return yield* createStore(options).pipe(Effect.catchAllDefect((cause) => UnknownError.make({ cause })));
|
|
85
|
-
}).pipe(Effect.withSpan(`StoreRegistry.lookup:${key.options.storeId}`)),
|
|
86
|
-
// TODO: Make idleTimeToLive vary for each store when Effect supports per-resource TTL
|
|
87
|
-
// See https://github.com/livestorejs/livestore/issues/917
|
|
88
|
-
idleTimeToLive: params.defaultOptions?.unusedCacheTime ?? DEFAULT_UNUSED_CACHE_TIME,
|
|
89
|
-
}).pipe(Runtime.runSync(this.#runtime));
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Gets a cached store or loads a new one, with the store lifetime scoped to the caller.
|
|
93
|
-
*
|
|
94
|
-
* @typeParam TSchema - The schema type for the store
|
|
95
|
-
* @returns An Effect that yields the store, scoped to the provided Scope
|
|
96
|
-
*
|
|
97
|
-
* @remarks
|
|
98
|
-
* - Stores are kept in cache and reused while any scope holds them
|
|
99
|
-
* - When the scope closes, the reference is released; the store is disposed after `unusedCacheTime`
|
|
100
|
-
* if no other scopes retain it
|
|
101
|
-
* - Concurrent calls with the same storeId share the same store instance
|
|
102
|
-
*/
|
|
103
|
-
getOrLoad = (options) => Effect.gen(this, function* () {
|
|
104
|
-
const key = new StoreCacheKey(options);
|
|
105
|
-
const store = yield* RcMap.get(this.#rcMap, key);
|
|
106
|
-
return store;
|
|
107
|
-
}).pipe(Effect.withSpan(`StoreRegistry.getOrLoad:${options.storeId}`));
|
|
108
|
-
/**
|
|
109
|
-
* Get or load a store, returning it directly if already loaded or a promise if loading.
|
|
110
|
-
*
|
|
111
|
-
* @typeParam TSchema - The schema type for the store
|
|
112
|
-
* @returns The loaded store if available, or a Promise that resolves to the loaded store
|
|
113
|
-
* @throws unknown loading error
|
|
114
|
-
*
|
|
115
|
-
* @remarks
|
|
116
|
-
* - Returns the store instance directly (synchronous) when already loaded
|
|
117
|
-
* - Returns a stable Promise reference when loading is in progress or needs to be initiated
|
|
118
|
-
* - Throws with the same error instance on subsequent calls after failure
|
|
119
|
-
* - Applies default options from registry config, with call-site options taking precedence
|
|
120
|
-
* - Concurrent calls with the same storeId share the same store instance
|
|
121
|
-
*/
|
|
122
|
-
getOrLoadPromise = (options) => {
|
|
123
|
-
const exit = this.getOrLoad(options).pipe(Effect.scoped, Runtime.runSyncExit(this.#runtime));
|
|
124
|
-
if (Exit.isSuccess(exit))
|
|
125
|
-
return exit.value;
|
|
126
|
-
// Check if the failure is due to async work
|
|
127
|
-
const defect = Cause.dieOption(exit.cause);
|
|
128
|
-
if (defect._tag === 'Some' && Runtime.isAsyncFiberException(defect.value)) {
|
|
129
|
-
const { storeId } = options;
|
|
130
|
-
// Return cached promise if one exists (ensures concurrent calls get the same Promise reference)
|
|
131
|
-
const cached = this.#loadingPromises.get(storeId);
|
|
132
|
-
if (cached)
|
|
133
|
-
return cached;
|
|
134
|
-
// Create and cache the promise
|
|
135
|
-
const fiber = defect.value.fiber;
|
|
136
|
-
const promise = Fiber.join(fiber)
|
|
137
|
-
.pipe(Runtime.runPromise(this.#runtime))
|
|
138
|
-
.finally(() => this.#loadingPromises.delete(storeId));
|
|
139
|
-
this.#loadingPromises.set(storeId, promise);
|
|
140
|
-
return promise;
|
|
141
|
-
}
|
|
142
|
-
// Handle synchronous failure
|
|
143
|
-
throw Cause.squash(exit.cause);
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Retains the store in cache until the returned release function is called.
|
|
147
|
-
*
|
|
148
|
-
* @returns A release function that, when called, removes this retention hold
|
|
149
|
-
*
|
|
150
|
-
* @remarks
|
|
151
|
-
* - Multiple retains on the same store are independent; each must be released separately
|
|
152
|
-
* - If the store isn't cached yet, it will be loaded and then retained
|
|
153
|
-
*/
|
|
154
|
-
retain = (options) => {
|
|
155
|
-
const release = Effect.gen(this, function* () {
|
|
156
|
-
const key = new StoreCacheKey(options);
|
|
157
|
-
yield* RcMap.get(this.#rcMap, key);
|
|
158
|
-
// Effect.never suspends indefinitely, keeping the RcMap reference alive.
|
|
159
|
-
// When `release()` is called, the fiber is interrupted, closing the scope
|
|
160
|
-
// and releasing the RcMap entry (which may trigger disposal after idleTimeToLive).
|
|
161
|
-
yield* Effect.never;
|
|
162
|
-
}).pipe(Effect.scoped, Runtime.runCallback(this.#runtime));
|
|
163
|
-
return () => release();
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Warms the cache for a store without adding a retention.
|
|
167
|
-
*
|
|
168
|
-
* @typeParam TSchema - The schema of the store to preload
|
|
169
|
-
* @returns A promise that resolves when the loading is complete (success or failure)
|
|
170
|
-
*
|
|
171
|
-
* @remarks
|
|
172
|
-
* - We don't return the store or throw as this is a fire-and-forget operation.
|
|
173
|
-
* - If the entry remains unused after preload resolves/rejects, it is scheduled for disposal.
|
|
174
|
-
*/
|
|
175
|
-
preload = async (options) => {
|
|
176
|
-
try {
|
|
177
|
-
await this.getOrLoadPromise(options);
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
// Do nothing; preload is best-effort
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
//# sourceMappingURL=StoreRegistry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistry.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAE/D,OAAO,EAAE,WAAW,EAAc,MAAM,sBAAsB,CAAA;AAC9D,OAAO,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EAEd,KAAK,EACL,OAAO,GAER,MAAM,yBAAyB,CAAA;AAGhC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAA;AA+B1G;;;;;;;;;;GAUG;AACH,MAAM,aAAa;IACR,OAAO,CAA6B;IAE7C,YAAY,OAAoC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAiB;QAC9B,OAAO,IAAI,YAAY,aAAa,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;IACvF,CAAC;IAED,CAAC,IAAI,CAAC,MAAM,CAAC;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB;;;OAGG;IACH,MAAM,CAAsD;IAE5D;;;OAGG;IACH,QAAQ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gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAA4B,CAAA;YAElF,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC3C,OAAO,OAAO,CAAA;QAChB,CAAC;QAED,6BAA6B;QAC7B,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC,CAAA;IAED;;;;;;;;OAQG;IACH,MAAM,GAAG,CAAC,OAAgC,EAAgB,EAAE;QAC1D,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;YACxC,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YAClC,yEAAyE;YACzE,0EAA0E;YAC1E,mFAAmF;YACnF,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAA;QACrB,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;QAE1D,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC,CAAA;IAED;;;;;;;;;OASG;IACH,OAAO,GAAG,KAAK,EAAmC,OAAoC,EAAiB,EAAE;QACvG,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC,CAAA;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistry.test.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistry.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { makeInMemoryAdapter } from '@livestore/adapter-web';
|
|
2
|
-
import { UnknownError } from '@livestore/common';
|
|
3
|
-
import { StoreInternalsSymbol } from '@livestore/livestore';
|
|
4
|
-
import { sleep } from '@livestore/utils';
|
|
5
|
-
import { Effect } from '@livestore/utils/effect';
|
|
6
|
-
import { describe, expect, it } from 'vitest';
|
|
7
|
-
import { schema } from "../../__tests__/fixture.js";
|
|
8
|
-
import { StoreRegistry } from "./StoreRegistry.js";
|
|
9
|
-
import { storeOptions } from "./storeOptions.js";
|
|
10
|
-
describe('StoreRegistry', () => {
|
|
11
|
-
it('returns a promise when the store is loading', async () => {
|
|
12
|
-
const registry = new StoreRegistry();
|
|
13
|
-
const result = registry.getOrLoadPromise(testStoreOptions());
|
|
14
|
-
expect(result).toBeInstanceOf(Promise);
|
|
15
|
-
// Clean up
|
|
16
|
-
const store = await result;
|
|
17
|
-
await store.shutdownPromise();
|
|
18
|
-
});
|
|
19
|
-
it('returns cached store synchronously after first load resolves', async () => {
|
|
20
|
-
const registry = new StoreRegistry();
|
|
21
|
-
const initial = registry.getOrLoadPromise(testStoreOptions());
|
|
22
|
-
expect(initial).toBeInstanceOf(Promise);
|
|
23
|
-
const store = await initial;
|
|
24
|
-
const cached = registry.getOrLoadPromise(testStoreOptions());
|
|
25
|
-
expect(cached).toBe(store);
|
|
26
|
-
expect(cached).not.toBeInstanceOf(Promise);
|
|
27
|
-
// Clean up
|
|
28
|
-
await store.shutdownPromise();
|
|
29
|
-
});
|
|
30
|
-
it('reuses the same promise for concurrent getOrLoadPromise calls while loading', async () => {
|
|
31
|
-
const registry = new StoreRegistry();
|
|
32
|
-
const options = testStoreOptions();
|
|
33
|
-
const first = registry.getOrLoadPromise(options);
|
|
34
|
-
const second = registry.getOrLoadPromise(options);
|
|
35
|
-
// Both should be the same promise
|
|
36
|
-
expect(first).toBe(second);
|
|
37
|
-
expect(first).toBeInstanceOf(Promise);
|
|
38
|
-
const store = await first;
|
|
39
|
-
// Both promises should resolve to the same store
|
|
40
|
-
expect(await second).toBe(store);
|
|
41
|
-
// Clean up
|
|
42
|
-
await store.shutdownPromise();
|
|
43
|
-
});
|
|
44
|
-
it('throws synchronously and rethrows on subsequent calls for sync failures', () => {
|
|
45
|
-
const registry = new StoreRegistry();
|
|
46
|
-
const badOptions = testStoreOptions({
|
|
47
|
-
// @ts-expect-error - intentionally passing invalid adapter to trigger error
|
|
48
|
-
adapter: null,
|
|
49
|
-
});
|
|
50
|
-
// First call throws synchronously
|
|
51
|
-
expect(() => registry.getOrLoadPromise(badOptions)).toThrow();
|
|
52
|
-
// Subsequent call should also throw synchronously (cached error)
|
|
53
|
-
expect(() => registry.getOrLoadPromise(badOptions)).toThrow();
|
|
54
|
-
});
|
|
55
|
-
it('caches and rethrows rejection on subsequent calls for async failures', async () => {
|
|
56
|
-
const registry = new StoreRegistry();
|
|
57
|
-
// Create an adapter that fails asynchronously (after yielding to the event loop)
|
|
58
|
-
const failingAdapter = () => Effect.gen(function* () {
|
|
59
|
-
yield* Effect.sleep(0); // Force async execution
|
|
60
|
-
return yield* UnknownError.make({ cause: new Error('Async failure') });
|
|
61
|
-
});
|
|
62
|
-
const badOptions = testStoreOptions({
|
|
63
|
-
adapter: failingAdapter,
|
|
64
|
-
});
|
|
65
|
-
// First call returns a promise that rejects
|
|
66
|
-
await expect(registry.getOrLoadPromise(badOptions)).rejects.toThrow();
|
|
67
|
-
// Subsequent call should throw the cached error synchronously (RcMap caches failures)
|
|
68
|
-
expect(() => registry.getOrLoadPromise(badOptions)).toThrow();
|
|
69
|
-
});
|
|
70
|
-
it('throws the same error instance on multiple calls after failure', async () => {
|
|
71
|
-
const registry = new StoreRegistry();
|
|
72
|
-
// Create an adapter that fails asynchronously
|
|
73
|
-
const failingAdapter = () => Effect.gen(function* () {
|
|
74
|
-
yield* Effect.sleep(0); // Force async execution
|
|
75
|
-
return yield* UnknownError.make({ cause: new Error('Async failure') });
|
|
76
|
-
});
|
|
77
|
-
const badOptions = testStoreOptions({
|
|
78
|
-
adapter: failingAdapter,
|
|
79
|
-
});
|
|
80
|
-
// Wait for the first failure
|
|
81
|
-
await expect(registry.getOrLoadPromise(badOptions)).rejects.toThrow();
|
|
82
|
-
// Capture the errors from subsequent calls
|
|
83
|
-
let error1;
|
|
84
|
-
let error2;
|
|
85
|
-
try {
|
|
86
|
-
registry.getOrLoadPromise(badOptions);
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
error1 = err;
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
registry.getOrLoadPromise(badOptions);
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
error2 = err;
|
|
96
|
-
}
|
|
97
|
-
// Both should be the exact same error instance (cached)
|
|
98
|
-
expect(error1).toBeDefined();
|
|
99
|
-
expect(error1).toBe(error2);
|
|
100
|
-
});
|
|
101
|
-
it('disposes store after unusedCacheTime expires', async () => {
|
|
102
|
-
const unusedCacheTime = 25;
|
|
103
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
104
|
-
const options = testStoreOptions();
|
|
105
|
-
const store = await registry.getOrLoadPromise(options);
|
|
106
|
-
// Store should be cached
|
|
107
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
108
|
-
// Wait for disposal
|
|
109
|
-
await sleep(unusedCacheTime + 50);
|
|
110
|
-
// After disposal, store should be removed
|
|
111
|
-
// The store is removed from cache, so next getOrLoadStore creates a new one
|
|
112
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
113
|
-
// Should be a different store instance
|
|
114
|
-
expect(nextStore).not.toBe(store);
|
|
115
|
-
expect(nextStore[StoreInternalsSymbol].clientSession.debugInstanceId).toBeDefined();
|
|
116
|
-
// Clean up the second store (first one was disposed)
|
|
117
|
-
await nextStore.shutdownPromise();
|
|
118
|
-
});
|
|
119
|
-
it('does not dispose when unusedCacheTime is Infinity', async () => {
|
|
120
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime: Number.POSITIVE_INFINITY } });
|
|
121
|
-
const options = testStoreOptions();
|
|
122
|
-
const store = await registry.getOrLoadPromise(options);
|
|
123
|
-
// Store should be cached
|
|
124
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
125
|
-
// Wait a reasonable duration to verify no disposal
|
|
126
|
-
await sleep(100);
|
|
127
|
-
// Store should still be cached (not disposed)
|
|
128
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
129
|
-
// Clean up manually
|
|
130
|
-
await store.shutdownPromise();
|
|
131
|
-
});
|
|
132
|
-
it('schedules disposal if store becomes unused during loading', async () => {
|
|
133
|
-
const unusedCacheTime = 50;
|
|
134
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
135
|
-
const options = testStoreOptions();
|
|
136
|
-
// Start loading without any retain
|
|
137
|
-
const storePromise = registry.getOrLoadPromise(options);
|
|
138
|
-
// Wait for store to load (no retain registered)
|
|
139
|
-
const store = await storePromise;
|
|
140
|
-
// Since there were no retain when loading completed, disposal should be scheduled
|
|
141
|
-
await sleep(unusedCacheTime + 50);
|
|
142
|
-
// Store should be disposed
|
|
143
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
144
|
-
expect(nextStore).not.toBe(store);
|
|
145
|
-
await nextStore.shutdownPromise();
|
|
146
|
-
});
|
|
147
|
-
// This test is skipped because Effect doesn't yet support different `idleTimeToLive` values for each resource in `RcMap`
|
|
148
|
-
// See https://github.com/livestorejs/livestore/issues/917
|
|
149
|
-
it.skip('allows call-site options to override default options', async () => {
|
|
150
|
-
const registry = new StoreRegistry({
|
|
151
|
-
defaultOptions: {
|
|
152
|
-
unusedCacheTime: 1000, // Default is long
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
const options = testStoreOptions({
|
|
156
|
-
unusedCacheTime: 10, // Override with shorter time
|
|
157
|
-
});
|
|
158
|
-
const store = await registry.getOrLoadPromise(options);
|
|
159
|
-
// Wait for the override time (10ms)
|
|
160
|
-
await sleep(10);
|
|
161
|
-
// Should be disposed according to the override time, not default
|
|
162
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
163
|
-
expect(nextStore).not.toBe(store);
|
|
164
|
-
await nextStore.shutdownPromise();
|
|
165
|
-
});
|
|
166
|
-
// This test is skipped because we don't yet support dynamic `unusedCacheTime` updates for cached stores.
|
|
167
|
-
// See https://github.com/livestorejs/livestore/issues/918
|
|
168
|
-
it.skip('keeps the longest unusedCacheTime seen for a store when options vary across calls', async () => {
|
|
169
|
-
const registry = new StoreRegistry();
|
|
170
|
-
const options = testStoreOptions({ unusedCacheTime: 10 });
|
|
171
|
-
const release = registry.retain(options);
|
|
172
|
-
const store = await registry.getOrLoadPromise(options);
|
|
173
|
-
// Call with longer unusedCacheTime
|
|
174
|
-
await registry.getOrLoadPromise(testStoreOptions({ unusedCacheTime: 100 }));
|
|
175
|
-
release();
|
|
176
|
-
// After 99ms, store should still be alive (100ms unusedCacheTime used)
|
|
177
|
-
await sleep(99);
|
|
178
|
-
// Store should still be cached
|
|
179
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
180
|
-
// After the full 100ms, store should be disposed
|
|
181
|
-
await sleep(1);
|
|
182
|
-
// Next getOrLoadStore should create a new store
|
|
183
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
184
|
-
expect(nextStore).not.toBe(store);
|
|
185
|
-
// Clean up the second store (first one was disposed)
|
|
186
|
-
await nextStore.shutdownPromise();
|
|
187
|
-
});
|
|
188
|
-
it('preload does not throw', async () => {
|
|
189
|
-
const registry = new StoreRegistry();
|
|
190
|
-
// Create invalid options that would cause an error
|
|
191
|
-
const badOptions = testStoreOptions({
|
|
192
|
-
// @ts-expect-error - intentionally passing invalid adapter to trigger error
|
|
193
|
-
adapter: null,
|
|
194
|
-
});
|
|
195
|
-
// preload should not throw
|
|
196
|
-
await expect(registry.preload(badOptions)).resolves.toBeUndefined();
|
|
197
|
-
// But subsequent getOrLoadStore should throw the cached error
|
|
198
|
-
expect(() => registry.getOrLoadPromise(badOptions)).toThrow();
|
|
199
|
-
});
|
|
200
|
-
it('handles rapid retain/release cycles without errors', async () => {
|
|
201
|
-
const unusedCacheTime = 50;
|
|
202
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
203
|
-
const options = testStoreOptions();
|
|
204
|
-
const store = await registry.getOrLoadPromise(options);
|
|
205
|
-
// Rapidly retain and release multiple times
|
|
206
|
-
for (let i = 0; i < 10; i++) {
|
|
207
|
-
const release = registry.retain(options);
|
|
208
|
-
release();
|
|
209
|
-
}
|
|
210
|
-
// Wait for disposal to trigger
|
|
211
|
-
await sleep(unusedCacheTime + 50);
|
|
212
|
-
// Store should be disposed after the last release
|
|
213
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
214
|
-
expect(nextStore).not.toBe(store);
|
|
215
|
-
await nextStore.shutdownPromise();
|
|
216
|
-
});
|
|
217
|
-
it('cancels disposal when new retain', async () => {
|
|
218
|
-
const unusedCacheTime = 50;
|
|
219
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
220
|
-
const options = testStoreOptions();
|
|
221
|
-
const store = await registry.getOrLoadPromise(options);
|
|
222
|
-
// Wait almost to disposal threshold
|
|
223
|
-
await sleep(unusedCacheTime - 5);
|
|
224
|
-
// Add a new retain before disposal triggers
|
|
225
|
-
const release = registry.retain(options);
|
|
226
|
-
// Complete the original unusedCacheTime
|
|
227
|
-
await sleep(5);
|
|
228
|
-
// Store should not have been disposed because we added a retain
|
|
229
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
230
|
-
// Clean up
|
|
231
|
-
release();
|
|
232
|
-
await sleep(unusedCacheTime + 50);
|
|
233
|
-
// Now it should be disposed
|
|
234
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
235
|
-
expect(nextStore).not.toBe(store);
|
|
236
|
-
await nextStore.shutdownPromise();
|
|
237
|
-
});
|
|
238
|
-
it('aborts loading when disposal fires while store is still loading', async () => {
|
|
239
|
-
const unusedCacheTime = 10;
|
|
240
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
241
|
-
const options = testStoreOptions();
|
|
242
|
-
// Retain briefly to trigger getOrLoadStore and then release
|
|
243
|
-
const release = registry.retain(options);
|
|
244
|
-
// Start loading
|
|
245
|
-
const loadPromise = registry.getOrLoadPromise(options);
|
|
246
|
-
// Attach a catch handler to prevent unhandled rejection when the load is aborted
|
|
247
|
-
const abortedPromise = loadPromise.catch(() => {
|
|
248
|
-
// Expected: load was aborted by disposal
|
|
249
|
-
});
|
|
250
|
-
// Release immediately, which schedules disposal
|
|
251
|
-
release();
|
|
252
|
-
// Wait for disposal to trigger
|
|
253
|
-
await sleep(unusedCacheTime + 50);
|
|
254
|
-
// Wait for the abort to complete
|
|
255
|
-
await abortedPromise;
|
|
256
|
-
// After abort, a new getOrLoadStore should start a fresh load
|
|
257
|
-
const freshLoadPromise = registry.getOrLoadPromise(options);
|
|
258
|
-
// This should be a new promise (not the aborted one)
|
|
259
|
-
expect(freshLoadPromise).toBeInstanceOf(Promise);
|
|
260
|
-
expect(freshLoadPromise).not.toBe(loadPromise);
|
|
261
|
-
// Wait for fresh load to complete
|
|
262
|
-
const store = await freshLoadPromise;
|
|
263
|
-
expect(store).toBeDefined();
|
|
264
|
-
await store.shutdownPromise();
|
|
265
|
-
});
|
|
266
|
-
it('retain keeps store alive past unusedCacheTime', async () => {
|
|
267
|
-
const unusedCacheTime = 50;
|
|
268
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
269
|
-
const options = testStoreOptions();
|
|
270
|
-
// Load the store
|
|
271
|
-
const store = await registry.getOrLoadPromise(options);
|
|
272
|
-
// Retain the store before disposal could fire
|
|
273
|
-
const release = registry.retain(options);
|
|
274
|
-
// Wait past the unusedCacheTime
|
|
275
|
-
await sleep(unusedCacheTime + 50);
|
|
276
|
-
// Store should still be cached because retain keeps it alive
|
|
277
|
-
const cachedStore = registry.getOrLoadPromise(options);
|
|
278
|
-
expect(cachedStore).toBe(store);
|
|
279
|
-
release();
|
|
280
|
-
await store.shutdownPromise();
|
|
281
|
-
});
|
|
282
|
-
it('manages multiple stores with different IDs independently', async () => {
|
|
283
|
-
const unusedCacheTime = 50;
|
|
284
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
285
|
-
const options1 = testStoreOptions({ storeId: 'store-1' });
|
|
286
|
-
const options2 = testStoreOptions({ storeId: 'store-2' });
|
|
287
|
-
const store1 = await registry.getOrLoadPromise(options1);
|
|
288
|
-
const store2 = await registry.getOrLoadPromise(options2);
|
|
289
|
-
// Should be different store instances
|
|
290
|
-
expect(store1).not.toBe(store2);
|
|
291
|
-
// Both should be cached independently
|
|
292
|
-
expect(registry.getOrLoadPromise(options1)).toBe(store1);
|
|
293
|
-
expect(registry.getOrLoadPromise(options2)).toBe(store2);
|
|
294
|
-
// Wait for both stores to be disposed
|
|
295
|
-
await sleep(unusedCacheTime + 50);
|
|
296
|
-
// Both stores should be disposed, so next getOrLoadStore creates new ones
|
|
297
|
-
const newStore1 = await registry.getOrLoadPromise(options1);
|
|
298
|
-
expect(newStore1).not.toBe(store1);
|
|
299
|
-
const newStore2 = await registry.getOrLoadPromise(options2);
|
|
300
|
-
expect(newStore2).not.toBe(store2);
|
|
301
|
-
// Clean up
|
|
302
|
-
await newStore1.shutdownPromise();
|
|
303
|
-
await newStore2.shutdownPromise();
|
|
304
|
-
});
|
|
305
|
-
it('applies default options from constructor', async () => {
|
|
306
|
-
const registry = new StoreRegistry({
|
|
307
|
-
defaultOptions: {
|
|
308
|
-
unusedCacheTime: 100,
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
const options = testStoreOptions();
|
|
312
|
-
const store = await registry.getOrLoadPromise(options);
|
|
313
|
-
// Verify the store loads successfully
|
|
314
|
-
expect(store).toBeDefined();
|
|
315
|
-
expect(store[StoreInternalsSymbol].clientSession.debugInstanceId).toBeDefined();
|
|
316
|
-
// Verify configured default unusedCacheTime is applied by checking disposal doesn't happen before it
|
|
317
|
-
await sleep(50);
|
|
318
|
-
// Store should still be cached after 50ms (default is 100ms)
|
|
319
|
-
expect(registry.getOrLoadPromise(options)).toBe(store);
|
|
320
|
-
await store.shutdownPromise();
|
|
321
|
-
});
|
|
322
|
-
it('prevents getOrLoadStore from returning a dying store', async () => {
|
|
323
|
-
const unusedCacheTime = 25;
|
|
324
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
325
|
-
const options = testStoreOptions();
|
|
326
|
-
// Load the store and wait for it to be ready
|
|
327
|
-
const originalStore = await registry.getOrLoadPromise(options);
|
|
328
|
-
// Verify store is cached
|
|
329
|
-
expect(registry.getOrLoadPromise(options)).toBe(originalStore);
|
|
330
|
-
// Wait for disposal to trigger
|
|
331
|
-
await sleep(unusedCacheTime + 50);
|
|
332
|
-
// After disposal, the cache should be cleared
|
|
333
|
-
// Calling getOrLoadStore should start a fresh load (return Promise)
|
|
334
|
-
const storeOrPromise = registry.getOrLoadPromise(options);
|
|
335
|
-
if (!(storeOrPromise instanceof Promise)) {
|
|
336
|
-
expect.fail('getOrLoadStore returned dying store synchronously instead of starting fresh load');
|
|
337
|
-
}
|
|
338
|
-
const freshStore = await storeOrPromise;
|
|
339
|
-
// A fresh load was triggered because cache was cleared
|
|
340
|
-
expect(freshStore).not.toBe(originalStore);
|
|
341
|
-
await freshStore.shutdownPromise();
|
|
342
|
-
});
|
|
343
|
-
it('warms the cache so subsequent getOrLoadStore is synchronous after preload', async () => {
|
|
344
|
-
const registry = new StoreRegistry();
|
|
345
|
-
const options = testStoreOptions();
|
|
346
|
-
// Preload the store
|
|
347
|
-
await registry.preload(options);
|
|
348
|
-
// Subsequent getOrLoadStore should return synchronously (not a Promise)
|
|
349
|
-
const store = registry.getOrLoadPromise(options);
|
|
350
|
-
expect(store).not.toBeInstanceOf(Promise);
|
|
351
|
-
// TypeScript doesn't narrow the type, so we need to assert
|
|
352
|
-
if (store instanceof Promise) {
|
|
353
|
-
throw new Error('Expected store, got Promise');
|
|
354
|
-
}
|
|
355
|
-
// Clean up
|
|
356
|
-
await store.shutdownPromise();
|
|
357
|
-
});
|
|
358
|
-
it('schedules disposal after preload if no retainers are added', async () => {
|
|
359
|
-
const unusedCacheTime = 50;
|
|
360
|
-
const registry = new StoreRegistry({ defaultOptions: { unusedCacheTime } });
|
|
361
|
-
const options = testStoreOptions();
|
|
362
|
-
// Preload without retaining
|
|
363
|
-
await registry.preload(options);
|
|
364
|
-
// Get the store
|
|
365
|
-
const store = registry.getOrLoadPromise(options);
|
|
366
|
-
expect(store).not.toBeInstanceOf(Promise);
|
|
367
|
-
// Wait for disposal to trigger
|
|
368
|
-
await sleep(unusedCacheTime + 50);
|
|
369
|
-
// Store should be disposed since no retainers were added
|
|
370
|
-
const nextStore = await registry.getOrLoadPromise(options);
|
|
371
|
-
expect(nextStore).not.toBe(store);
|
|
372
|
-
await nextStore.shutdownPromise();
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
const testStoreOptions = (overrides = {}) => storeOptions({
|
|
376
|
-
storeId: 'test-store',
|
|
377
|
-
schema,
|
|
378
|
-
adapter: makeInMemoryAdapter(),
|
|
379
|
-
...overrides,
|
|
380
|
-
});
|
|
381
|
-
//# sourceMappingURL=StoreRegistry.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRegistry.test.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/StoreRegistry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM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,OAAO,CAAC,OAAO,CAAC,CAAA;QAE/B,gBAAgB;QAChB,MAAM,KAAK,GAAG,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QAChD,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QAEzC,+BAA+B;QAC/B,MAAM,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC,CAAA;QAEjC,yDAAyD;QACzD,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QAC1D,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAEjC,MAAM,SAAS,CAAC,eAAe,EAAE,CAAA;IACnC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,YAAwD,EAAE,EAAE,EAAE,CACtF,YAAY,CAAC;IACX,OAAO,EAAE,YAAY;IACrB,MAAM;IACN,OAAO,EAAE,mBAAmB,EAAE;IAC9B,GAAG,SAAS;CACb,CAAC,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { StoreRegistry } from './StoreRegistry.ts';
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,15 +0,0 @@
|
|
|
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 <StoreRegistryProvider>');
|
|
13
|
-
return storeRegistry;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=StoreRegistryContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,gEAAgE,CAAC,CAAA;IAErG,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
|