@livestore/react 0.3.0-dev.17 → 0.3.0-dev.18
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.
|
@@ -2,7 +2,7 @@ import type { Adapter, BootStatus, IntentionalShutdownCause, MigrationsReport }
|
|
|
2
2
|
import { UnexpectedError } from '@livestore/common';
|
|
3
3
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
4
4
|
import type { BaseGraphQLContext, GraphQLOptions, OtelOptions, Store } from '@livestore/livestore';
|
|
5
|
-
import {
|
|
5
|
+
import { StoreInterrupted } from '@livestore/livestore';
|
|
6
6
|
import type { OtelTracer } from '@livestore/utils/effect';
|
|
7
7
|
import { Effect } from '@livestore/utils/effect';
|
|
8
8
|
import type * as otel from '@opentelemetry/api';
|
|
@@ -29,7 +29,7 @@ interface LiveStoreProviderProps<GraphQLContext extends BaseGraphQLContext> {
|
|
|
29
29
|
otelOptions?: Partial<OtelOptions>;
|
|
30
30
|
renderLoading: (status: BootStatus) => ReactElement;
|
|
31
31
|
renderError?: (error: UnexpectedError | unknown) => ReactElement;
|
|
32
|
-
renderShutdown?: (cause: IntentionalShutdownCause |
|
|
32
|
+
renderShutdown?: (cause: IntentionalShutdownCause | StoreInterrupted) => ReactElement;
|
|
33
33
|
adapter: Adapter;
|
|
34
34
|
/**
|
|
35
35
|
* In order for LiveStore to apply multiple mutations in a single render,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACxG,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EACV,kBAAkB,EAElB,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cAAc,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAClC,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,YAAY,CAAA;IACnD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,KAAK,YAAY,CAAA;IAChE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,GAAG,gBAAgB,KAAK,YAAY,CAAA;IACrF,OAAO,EAAE,OAAO,CAAA;IAChB;;;;;;;;;;;OAWG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IACvC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAoBD,eAAO,MAAM,iBAAiB,GAAI,cAAc,SAAS,kBAAkB,EAAE,+JAc1E,sBAAsB,CAAC,cAAc,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,KAAK,CAAC,YAgC5E,CAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { provideOtel, UnexpectedError } from '@livestore/common';
|
|
2
|
-
import { createStore,
|
|
2
|
+
import { createStore, StoreInterrupted } from '@livestore/livestore';
|
|
3
3
|
import { errorToString, LS_DEV } from '@livestore/utils';
|
|
4
4
|
import { Deferred, Effect, Exit, identity, Logger, LogLevel, Schema, Scope, TaskTracing } from '@livestore/utils/effect';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { LiveStoreContext } from './LiveStoreContext.js';
|
|
7
7
|
const defaultRenderError = (error) => (React.createElement(React.Fragment, null, Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)));
|
|
8
8
|
const defaultRenderShutdown = (cause) => {
|
|
9
|
-
const reason = cause._tag === 'LiveStore.
|
|
10
|
-
?
|
|
9
|
+
const reason = cause._tag === 'LiveStore.StoreInterrupted'
|
|
10
|
+
? `interrupted due to: ${cause.reason}`
|
|
11
11
|
: cause.reason === 'devtools-import'
|
|
12
12
|
? 'devtools import'
|
|
13
13
|
: cause.reason === 'devtools-reset'
|
|
@@ -99,7 +99,7 @@ const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, ad
|
|
|
99
99
|
signal,
|
|
100
100
|
};
|
|
101
101
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
102
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted());
|
|
102
|
+
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 're-rendering due to changed input props' }));
|
|
103
103
|
ctxValueRef.current.componentScope = undefined;
|
|
104
104
|
ctxValueRef.current.shutdownDeferred = undefined;
|
|
105
105
|
}
|
|
@@ -122,7 +122,7 @@ const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, ad
|
|
|
122
122
|
if (ctxValueRef.current.componentScope !== undefined &&
|
|
123
123
|
ctxValueRef.current.shutdownDeferred !== undefined &&
|
|
124
124
|
ctxValueRef.current.counter === counter) {
|
|
125
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new
|
|
125
|
+
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'Aborted via provided AbortController' }));
|
|
126
126
|
ctxValueRef.current.componentScope = undefined;
|
|
127
127
|
ctxValueRef.current.shutdownDeferred = undefined;
|
|
128
128
|
}
|
|
@@ -152,7 +152,7 @@ const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, ad
|
|
|
152
152
|
setContextValue({ stage: 'running', store });
|
|
153
153
|
}).pipe(Scope.extend(componentScope), Effect.forkIn(componentScope));
|
|
154
154
|
const shutdownContext = (cause) => Effect.sync(() => setContextValue({ stage: 'shutdown', cause }));
|
|
155
|
-
yield* Deferred.await(shutdownDeferred).pipe(Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] shutdown', cause)), Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)), Effect.catchTag('LiveStore.
|
|
155
|
+
yield* Deferred.await(shutdownDeferred).pipe(Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] shutdown', cause)), Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)), Effect.catchTag('LiveStore.StoreInterrupted', (cause) => shutdownContext(cause)), Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))), Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))), Effect.exit);
|
|
156
156
|
}).pipe(Effect.scoped,
|
|
157
157
|
// NOTE we're running the code above in a semaphore to make sure a previous store is always fully
|
|
158
158
|
// shutdown before a new one is created - especially when shutdown logic is async. You can't trust `React.useEffect`.
|
|
@@ -160,7 +160,7 @@ const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, ad
|
|
|
160
160
|
withSemaphore(storeId), Effect.withSpan('@livestore/react:useCreateStore'), LS_DEV ? TaskTracing.withAsyncTaggingTracing((name) => console.createTask(name)) : identity, provideOtel({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer }), Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: 'window' }), Effect.provide(Logger.prettyWithThread('window')), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runFork);
|
|
161
161
|
return () => {
|
|
162
162
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
163
|
-
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted());
|
|
163
|
+
interrupt(ctxValueRef.current.componentScope, ctxValueRef.current.shutdownDeferred, new StoreInterrupted({ reason: 'unmounting component' }));
|
|
164
164
|
ctxValueRef.current.componentScope = undefined;
|
|
165
165
|
ctxValueRef.current.shutdownDeferred = undefined;
|
|
166
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAWhE,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../src/LiveStoreProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAWhE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAGxH,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AA0CxD,MAAM,kBAAkB,GAAG,CAAC,KAAgC,EAAE,EAAE,CAAC,CAC/D,0CAAG,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAI,CACnF,CAAA;AACD,MAAM,qBAAqB,GAAG,CAAC,KAAkD,EAAE,EAAE;IACnF,MAAM,MAAM,GACV,KAAK,CAAC,IAAI,KAAK,4BAA4B;QACzC,CAAC,CAAC,uBAAuB,KAAK,CAAC,MAAM,EAAE;QACvC,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,iBAAiB;YAClC,CAAC,CA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react",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@opentelemetry/api": "1.9.0",
|
|
26
|
-
"@livestore/common": "0.3.0-dev.
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/
|
|
26
|
+
"@livestore/common": "0.3.0-dev.18",
|
|
27
|
+
"@livestore/livestore": "0.3.0-dev.18",
|
|
28
|
+
"@livestore/utils": "0.3.0-dev.18"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"typescript": "^5.7.3",
|
|
40
40
|
"vite": "^6.1.0",
|
|
41
41
|
"vitest": "^2.1.4",
|
|
42
|
-
"@livestore/adapter-web": "0.3.0-dev.
|
|
42
|
+
"@livestore/adapter-web": "0.3.0-dev.18"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "~19.0.0"
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
ShutdownDeferred,
|
|
11
11
|
Store,
|
|
12
12
|
} from '@livestore/livestore'
|
|
13
|
-
import { createStore,
|
|
13
|
+
import { createStore, StoreInterrupted } from '@livestore/livestore'
|
|
14
14
|
import { errorToString, LS_DEV } from '@livestore/utils'
|
|
15
15
|
import type { OtelTracer } from '@livestore/utils/effect'
|
|
16
16
|
import { Deferred, Effect, Exit, identity, Logger, LogLevel, Schema, Scope, TaskTracing } from '@livestore/utils/effect'
|
|
@@ -41,7 +41,7 @@ interface LiveStoreProviderProps<GraphQLContext extends BaseGraphQLContext> {
|
|
|
41
41
|
otelOptions?: Partial<OtelOptions>
|
|
42
42
|
renderLoading: (status: BootStatus) => ReactElement
|
|
43
43
|
renderError?: (error: UnexpectedError | unknown) => ReactElement
|
|
44
|
-
renderShutdown?: (cause: IntentionalShutdownCause |
|
|
44
|
+
renderShutdown?: (cause: IntentionalShutdownCause | StoreInterrupted) => ReactElement
|
|
45
45
|
adapter: Adapter
|
|
46
46
|
/**
|
|
47
47
|
* In order for LiveStore to apply multiple mutations in a single render,
|
|
@@ -63,10 +63,10 @@ interface LiveStoreProviderProps<GraphQLContext extends BaseGraphQLContext> {
|
|
|
63
63
|
const defaultRenderError = (error: UnexpectedError | unknown) => (
|
|
64
64
|
<>{Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)}</>
|
|
65
65
|
)
|
|
66
|
-
const defaultRenderShutdown = (cause: IntentionalShutdownCause |
|
|
66
|
+
const defaultRenderShutdown = (cause: IntentionalShutdownCause | StoreInterrupted) => {
|
|
67
67
|
const reason =
|
|
68
|
-
cause._tag === 'LiveStore.
|
|
69
|
-
?
|
|
68
|
+
cause._tag === 'LiveStore.StoreInterrupted'
|
|
69
|
+
? `interrupted due to: ${cause.reason}`
|
|
70
70
|
: cause.reason === 'devtools-import'
|
|
71
71
|
? 'devtools import'
|
|
72
72
|
: cause.reason === 'devtools-reset'
|
|
@@ -181,7 +181,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
181
181
|
const interrupt = (
|
|
182
182
|
componentScope: Scope.CloseableScope,
|
|
183
183
|
shutdownDeferred: ShutdownDeferred,
|
|
184
|
-
error:
|
|
184
|
+
error: StoreInterrupted,
|
|
185
185
|
) =>
|
|
186
186
|
Effect.gen(function* () {
|
|
187
187
|
// console.log('[@livestore/livestore/react] interupting', error)
|
|
@@ -213,7 +213,11 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
213
213
|
signal,
|
|
214
214
|
}
|
|
215
215
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
216
|
-
interrupt(
|
|
216
|
+
interrupt(
|
|
217
|
+
ctxValueRef.current.componentScope,
|
|
218
|
+
ctxValueRef.current.shutdownDeferred,
|
|
219
|
+
new StoreInterrupted({ reason: 're-rendering due to changed input props' }),
|
|
220
|
+
)
|
|
217
221
|
ctxValueRef.current.componentScope = undefined
|
|
218
222
|
ctxValueRef.current.shutdownDeferred = undefined
|
|
219
223
|
}
|
|
@@ -240,7 +244,11 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
240
244
|
ctxValueRef.current.shutdownDeferred !== undefined &&
|
|
241
245
|
ctxValueRef.current.counter === counter
|
|
242
246
|
) {
|
|
243
|
-
interrupt(
|
|
247
|
+
interrupt(
|
|
248
|
+
ctxValueRef.current.componentScope,
|
|
249
|
+
ctxValueRef.current.shutdownDeferred,
|
|
250
|
+
new StoreInterrupted({ reason: 'Aborted via provided AbortController' }),
|
|
251
|
+
)
|
|
244
252
|
ctxValueRef.current.componentScope = undefined
|
|
245
253
|
ctxValueRef.current.shutdownDeferred = undefined
|
|
246
254
|
}
|
|
@@ -250,7 +258,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
250
258
|
const componentScope = yield* Scope.make()
|
|
251
259
|
const shutdownDeferred = yield* Deferred.make<
|
|
252
260
|
void,
|
|
253
|
-
UnexpectedError | IntentionalShutdownCause |
|
|
261
|
+
UnexpectedError | IntentionalShutdownCause | StoreInterrupted
|
|
254
262
|
>()
|
|
255
263
|
|
|
256
264
|
ctxValueRef.current.componentScope = componentScope
|
|
@@ -276,13 +284,13 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
276
284
|
setContextValue({ stage: 'running', store })
|
|
277
285
|
}).pipe(Scope.extend(componentScope), Effect.forkIn(componentScope))
|
|
278
286
|
|
|
279
|
-
const shutdownContext = (cause: IntentionalShutdownCause |
|
|
287
|
+
const shutdownContext = (cause: IntentionalShutdownCause | StoreInterrupted) =>
|
|
280
288
|
Effect.sync(() => setContextValue({ stage: 'shutdown', cause }))
|
|
281
289
|
|
|
282
290
|
yield* Deferred.await(shutdownDeferred).pipe(
|
|
283
291
|
Effect.tapErrorCause((cause) => Effect.logDebug('[@livestore/livestore/react] shutdown', cause)),
|
|
284
292
|
Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)),
|
|
285
|
-
Effect.catchTag('LiveStore.
|
|
293
|
+
Effect.catchTag('LiveStore.StoreInterrupted', (cause) => shutdownContext(cause)),
|
|
286
294
|
Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))),
|
|
287
295
|
Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))),
|
|
288
296
|
Effect.exit,
|
|
@@ -305,7 +313,11 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
|
305
313
|
|
|
306
314
|
return () => {
|
|
307
315
|
if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
|
|
308
|
-
interrupt(
|
|
316
|
+
interrupt(
|
|
317
|
+
ctxValueRef.current.componentScope,
|
|
318
|
+
ctxValueRef.current.shutdownDeferred,
|
|
319
|
+
new StoreInterrupted({ reason: 'unmounting component' }),
|
|
320
|
+
)
|
|
309
321
|
ctxValueRef.current.componentScope = undefined
|
|
310
322
|
ctxValueRef.current.shutdownDeferred = undefined
|
|
311
323
|
}
|
package/tmp/pack.tgz
ADDED
|
Binary file
|