@livestore/livestore 0.0.58-dev.1 → 0.0.58-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -117
- package/dist/.tsbuildinfo +1 -1
- package/dist/effect/LiveStore.d.ts +3 -3
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +1 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/global-state.d.ts.map +1 -1
- package/dist/global-state.js +2 -1
- package/dist/global-state.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +1 -1
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +1 -1
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +4 -4
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +2 -2
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/row-query.d.ts +3 -2
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +18 -10
- package/dist/row-query.js.map +1 -1
- package/dist/store-devtools.d.ts +2 -2
- package/dist/store-devtools.d.ts.map +1 -1
- package/dist/store-devtools.js +3 -3
- package/dist/store-devtools.js.map +1 -1
- package/dist/store.d.ts +23 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +90 -59
- package/dist/store.js.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +1 -0
- package/dist/utils/dev.js.map +1 -1
- package/dist/{react/utils → utils}/stack-info.d.ts +1 -2
- package/dist/utils/stack-info.d.ts.map +1 -0
- package/dist/{react/utils → utils}/stack-info.js +1 -9
- package/dist/utils/stack-info.js.map +1 -0
- package/dist/utils/stack-info.test.d.ts.map +1 -0
- package/dist/{__tests__/react/utils → utils}/stack-info.test.js +1 -1
- package/dist/utils/stack-info.test.js.map +1 -0
- package/dist/utils/tests/fixture.d.ts +259 -0
- package/dist/utils/tests/fixture.d.ts.map +1 -0
- package/dist/utils/tests/fixture.js +33 -0
- package/dist/utils/tests/fixture.js.map +1 -0
- package/dist/utils/tests/mod.d.ts +3 -0
- package/dist/utils/tests/mod.d.ts.map +1 -0
- package/dist/utils/tests/mod.js +3 -0
- package/dist/utils/tests/mod.js.map +1 -0
- package/dist/utils/tests/otel.d.ts.map +1 -0
- package/dist/utils/tests/otel.js.map +1 -0
- package/package.json +17 -24
- package/src/ambient.d.ts +3 -0
- package/src/effect/LiveStore.ts +4 -4
- package/src/global-state.ts +5 -1
- package/src/index.ts +17 -4
- package/src/reactiveQueries/base-class.ts +1 -1
- package/src/reactiveQueries/sql.test.ts +2 -2
- package/src/reactiveQueries/sql.ts +5 -5
- package/src/row-query.ts +36 -16
- package/src/store-devtools.ts +5 -5
- package/src/store.ts +146 -78
- package/src/utils/dev.ts +1 -0
- package/src/{__tests__/react/utils → utils}/stack-info.test.ts +1 -1
- package/src/{react/utils → utils}/stack-info.ts +2 -12
- package/src/utils/tests/fixture.ts +77 -0
- package/src/utils/tests/mod.ts +2 -0
- package/tsconfig.json +1 -2
- package/vitest.config.js +0 -8
- package/dist/__tests__/react/fixture.d.ts +0 -461
- package/dist/__tests__/react/fixture.d.ts.map +0 -1
- package/dist/__tests__/react/fixture.js +0 -68
- package/dist/__tests__/react/fixture.js.map +0 -1
- package/dist/__tests__/react/utils/otel.d.ts.map +0 -1
- package/dist/__tests__/react/utils/otel.js.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.d.ts.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.js.map +0 -1
- package/dist/react/LiveStoreContext.d.ts +0 -7
- package/dist/react/LiveStoreContext.d.ts.map +0 -1
- package/dist/react/LiveStoreContext.js +0 -13
- package/dist/react/LiveStoreContext.js.map +0 -1
- package/dist/react/LiveStoreProvider.d.ts +0 -47
- package/dist/react/LiveStoreProvider.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.js +0 -169
- package/dist/react/LiveStoreProvider.js.map +0 -1
- package/dist/react/LiveStoreProvider.test.d.ts +0 -2
- package/dist/react/LiveStoreProvider.test.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.test.js +0 -62
- package/dist/react/LiveStoreProvider.test.js.map +0 -1
- package/dist/react/components/LiveList.d.ts +0 -21
- package/dist/react/components/LiveList.d.ts.map +0 -1
- package/dist/react/components/LiveList.js +0 -31
- package/dist/react/components/LiveList.js.map +0 -1
- package/dist/react/index.d.ts +0 -11
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -10
- package/dist/react/index.js.map +0 -1
- package/dist/react/useAtom.d.ts +0 -10
- package/dist/react/useAtom.d.ts.map +0 -1
- package/dist/react/useAtom.js +0 -37
- package/dist/react/useAtom.js.map +0 -1
- package/dist/react/useLocalId.d.ts +0 -10
- package/dist/react/useLocalId.d.ts.map +0 -1
- package/dist/react/useLocalId.js +0 -21
- package/dist/react/useLocalId.js.map +0 -1
- package/dist/react/useQuery.d.ts +0 -9
- package/dist/react/useQuery.d.ts.map +0 -1
- package/dist/react/useQuery.js +0 -69
- package/dist/react/useQuery.js.map +0 -1
- package/dist/react/useQuery.test.d.ts +0 -2
- package/dist/react/useQuery.test.d.ts.map +0 -1
- package/dist/react/useQuery.test.js +0 -51
- package/dist/react/useQuery.test.js.map +0 -1
- package/dist/react/useRow.d.ts +0 -46
- package/dist/react/useRow.d.ts.map +0 -1
- package/dist/react/useRow.js +0 -94
- package/dist/react/useRow.js.map +0 -1
- package/dist/react/useRow.test.d.ts +0 -2
- package/dist/react/useRow.test.d.ts.map +0 -1
- package/dist/react/useRow.test.js +0 -562
- package/dist/react/useRow.test.js.map +0 -1
- package/dist/react/useTemporaryQuery.d.ts +0 -22
- package/dist/react/useTemporaryQuery.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.js +0 -70
- package/dist/react/useTemporaryQuery.js.map +0 -1
- package/dist/react/useTemporaryQuery.test.d.ts +0 -2
- package/dist/react/useTemporaryQuery.test.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.test.js +0 -37
- package/dist/react/useTemporaryQuery.test.js.map +0 -1
- package/dist/react/utils/stack-info.d.ts.map +0 -1
- package/dist/react/utils/stack-info.js.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +0 -13
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.js +0 -38
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +0 -1
- package/src/__tests__/react/fixture.tsx +0 -126
- package/src/react/LiveStoreContext.ts +0 -20
- package/src/react/LiveStoreProvider.test.tsx +0 -109
- package/src/react/LiveStoreProvider.tsx +0 -289
- package/src/react/components/LiveList.tsx +0 -84
- package/src/react/index.ts +0 -19
- package/src/react/useAtom.ts +0 -55
- package/src/react/useLocalId.ts +0 -33
- package/src/react/useQuery.test.tsx +0 -82
- package/src/react/useQuery.ts +0 -105
- package/src/react/useRow.test.tsx +0 -699
- package/src/react/useRow.ts +0 -180
- package/src/react/useTemporaryQuery.test.tsx +0 -56
- package/src/react/useTemporaryQuery.ts +0 -121
- package/src/react/utils/useStateRefWithReactiveInput.ts +0 -51
- /package/dist/{__tests__/react/utils → utils}/stack-info.test.d.ts +0 -0
- /package/dist/{__tests__/react/utils → utils/tests}/otel.d.ts +0 -0
- /package/dist/{__tests__/react/utils → utils/tests}/otel.js +0 -0
- /package/src/{__tests__/react/utils → utils/tests}/otel.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,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AAA;IACzB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAkBD,eAAO,MAAM,iBAAiB,GAAI,cAAc,SAAS,kBAAkB,iKAcxE,sBAAsB,CAAC,cAAc,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,GAAG,CAAC,OA6B1E,CAAA"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { UnexpectedError } from '@livestore/common';
|
|
2
|
-
import { errorToString } from '@livestore/utils';
|
|
3
|
-
import { Effect, FiberSet, Logger, LogLevel, Schema } from '@livestore/utils/effect';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { createStore } from '../store.js';
|
|
6
|
-
import { StoreAbort, StoreInterrupted } from '../store-context.js';
|
|
7
|
-
import { LiveStoreContext } from './LiveStoreContext.js';
|
|
8
|
-
const defaultRenderError = (error) => (React.createElement(React.Fragment, null, Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)));
|
|
9
|
-
const defaultRenderShutdown = (cause) => {
|
|
10
|
-
const reason = cause._tag === 'LiveStore.StoreAbort'
|
|
11
|
-
? 'abort signal'
|
|
12
|
-
: cause.reason === 'devtools-import'
|
|
13
|
-
? 'devtools import'
|
|
14
|
-
: cause.reason === 'devtools-reset'
|
|
15
|
-
? 'devtools reset'
|
|
16
|
-
: 'unknown reason';
|
|
17
|
-
return React.createElement(React.Fragment, null,
|
|
18
|
-
"LiveStore Shutdown due to ",
|
|
19
|
-
reason);
|
|
20
|
-
};
|
|
21
|
-
export const LiveStoreProvider = ({ renderLoading, renderError = defaultRenderError, renderShutdown = defaultRenderShutdown, graphQLOptions, otelOptions, children, schema, storeId = 'default', boot, adapter, batchUpdates, disableDevtools, signal, }) => {
|
|
22
|
-
const storeCtx = useCreateStore({
|
|
23
|
-
storeId,
|
|
24
|
-
schema,
|
|
25
|
-
graphQLOptions,
|
|
26
|
-
otelOptions,
|
|
27
|
-
boot,
|
|
28
|
-
adapter,
|
|
29
|
-
batchUpdates,
|
|
30
|
-
disableDevtools,
|
|
31
|
-
signal,
|
|
32
|
-
});
|
|
33
|
-
if (storeCtx.stage === 'error') {
|
|
34
|
-
return renderError(storeCtx.error);
|
|
35
|
-
}
|
|
36
|
-
if (storeCtx.stage === 'shutdown') {
|
|
37
|
-
return renderShutdown(storeCtx.cause);
|
|
38
|
-
}
|
|
39
|
-
if (storeCtx.stage !== 'running') {
|
|
40
|
-
return renderLoading(storeCtx);
|
|
41
|
-
}
|
|
42
|
-
window.__debugLiveStore ??= {};
|
|
43
|
-
window.__debugLiveStore[storeId] = storeCtx.store;
|
|
44
|
-
return React.createElement(LiveStoreContext.Provider, { value: storeCtx }, children);
|
|
45
|
-
};
|
|
46
|
-
const semaphoreMap = new Map();
|
|
47
|
-
const withSemaphore = (schemaKey) => {
|
|
48
|
-
let semaphore = semaphoreMap.get(schemaKey);
|
|
49
|
-
if (!semaphore) {
|
|
50
|
-
semaphore = Effect.makeSemaphore(1).pipe(Effect.runSync);
|
|
51
|
-
semaphoreMap.set(schemaKey, semaphore);
|
|
52
|
-
}
|
|
53
|
-
return semaphore.withPermits(1);
|
|
54
|
-
};
|
|
55
|
-
const useCreateStore = ({ schema, storeId, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, reactivityGraph, signal, }) => {
|
|
56
|
-
const [_, rerender] = React.useState(0);
|
|
57
|
-
const ctxValueRef = React.useRef({
|
|
58
|
-
value: { stage: 'loading' },
|
|
59
|
-
fiberSet: undefined,
|
|
60
|
-
counter: 0,
|
|
61
|
-
});
|
|
62
|
-
// console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
|
|
63
|
-
const inputPropsCacheRef = React.useRef({
|
|
64
|
-
schema,
|
|
65
|
-
graphQLOptions,
|
|
66
|
-
otelOptions,
|
|
67
|
-
boot,
|
|
68
|
-
adapter,
|
|
69
|
-
batchUpdates,
|
|
70
|
-
disableDevtools,
|
|
71
|
-
reactivityGraph,
|
|
72
|
-
signal,
|
|
73
|
-
});
|
|
74
|
-
const interrupt = (fiberSet, error) => Effect.gen(function* () {
|
|
75
|
-
yield* FiberSet.clear(fiberSet);
|
|
76
|
-
yield* FiberSet.run(fiberSet, Effect.fail(error));
|
|
77
|
-
}).pipe(Effect.tapErrorCause((cause) => Effect.logDebug(`[@livestore/livestore/react] interupting`, cause)), Effect.runFork);
|
|
78
|
-
if (inputPropsCacheRef.current.schema !== schema ||
|
|
79
|
-
inputPropsCacheRef.current.graphQLOptions !== graphQLOptions ||
|
|
80
|
-
inputPropsCacheRef.current.otelOptions !== otelOptions ||
|
|
81
|
-
inputPropsCacheRef.current.boot !== boot ||
|
|
82
|
-
inputPropsCacheRef.current.adapter !== adapter ||
|
|
83
|
-
inputPropsCacheRef.current.batchUpdates !== batchUpdates ||
|
|
84
|
-
inputPropsCacheRef.current.disableDevtools !== disableDevtools ||
|
|
85
|
-
inputPropsCacheRef.current.reactivityGraph !== reactivityGraph ||
|
|
86
|
-
inputPropsCacheRef.current.signal !== signal) {
|
|
87
|
-
inputPropsCacheRef.current = {
|
|
88
|
-
schema,
|
|
89
|
-
graphQLOptions,
|
|
90
|
-
otelOptions,
|
|
91
|
-
boot,
|
|
92
|
-
adapter,
|
|
93
|
-
batchUpdates,
|
|
94
|
-
disableDevtools,
|
|
95
|
-
reactivityGraph,
|
|
96
|
-
signal,
|
|
97
|
-
};
|
|
98
|
-
if (ctxValueRef.current.fiberSet !== undefined) {
|
|
99
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted());
|
|
100
|
-
ctxValueRef.current.fiberSet = undefined;
|
|
101
|
-
}
|
|
102
|
-
ctxValueRef.current = { value: { stage: 'loading' }, fiberSet: undefined, counter: ctxValueRef.current.counter + 1 };
|
|
103
|
-
}
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
const counter = ctxValueRef.current.counter;
|
|
106
|
-
const setContextValue = (value) => {
|
|
107
|
-
if (ctxValueRef.current.counter !== counter)
|
|
108
|
-
return;
|
|
109
|
-
ctxValueRef.current.value = value;
|
|
110
|
-
rerender((c) => c + 1);
|
|
111
|
-
};
|
|
112
|
-
signal?.addEventListener('abort', () => {
|
|
113
|
-
if (ctxValueRef.current.fiberSet !== undefined && ctxValueRef.current.counter === counter) {
|
|
114
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreAbort());
|
|
115
|
-
ctxValueRef.current.fiberSet = undefined;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
Effect.gen(function* () {
|
|
119
|
-
const fiberSet = yield* FiberSet.make();
|
|
120
|
-
ctxValueRef.current.fiberSet = fiberSet;
|
|
121
|
-
yield* Effect.gen(function* () {
|
|
122
|
-
const store = yield* createStore({
|
|
123
|
-
fiberSet,
|
|
124
|
-
schema,
|
|
125
|
-
storeId,
|
|
126
|
-
graphQLOptions,
|
|
127
|
-
otelOptions,
|
|
128
|
-
boot,
|
|
129
|
-
adapter,
|
|
130
|
-
reactivityGraph,
|
|
131
|
-
batchUpdates,
|
|
132
|
-
disableDevtools,
|
|
133
|
-
onBootStatus: (status) => {
|
|
134
|
-
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
|
|
135
|
-
return;
|
|
136
|
-
setContextValue(status);
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
setContextValue({ stage: 'running', store });
|
|
140
|
-
yield* Effect.never;
|
|
141
|
-
}).pipe(Effect.scoped, FiberSet.run(fiberSet));
|
|
142
|
-
const shutdownContext = (cause) => Effect.sync(() => setContextValue({ stage: 'shutdown', cause }));
|
|
143
|
-
yield* FiberSet.join(fiberSet).pipe(Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)), Effect.catchTag('LiveStore.StoreAbort', (cause) => shutdownContext(cause)), Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))), Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))), Effect.exit);
|
|
144
|
-
}).pipe(Effect.scoped,
|
|
145
|
-
// NOTE we're running the code above in a semaphore to make sure a previous store is always fully
|
|
146
|
-
// shutdown before a new one is created - especially when shutdown logic is async. You can't trust `React.useEffect`.
|
|
147
|
-
// Thank you to Mattia Manzati for this idea.
|
|
148
|
-
withSemaphore(storeId), Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: 'window' }), Effect.provide(Logger.pretty), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runFork);
|
|
149
|
-
return () => {
|
|
150
|
-
if (ctxValueRef.current.fiberSet !== undefined) {
|
|
151
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted());
|
|
152
|
-
ctxValueRef.current.fiberSet = undefined;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}, [
|
|
156
|
-
schema,
|
|
157
|
-
graphQLOptions,
|
|
158
|
-
otelOptions,
|
|
159
|
-
boot,
|
|
160
|
-
adapter,
|
|
161
|
-
batchUpdates,
|
|
162
|
-
disableDevtools,
|
|
163
|
-
signal,
|
|
164
|
-
reactivityGraph,
|
|
165
|
-
storeId,
|
|
166
|
-
]);
|
|
167
|
-
return ctxValueRef.current.value;
|
|
168
|
-
};
|
|
169
|
-
//# sourceMappingURL=LiveStoreProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGpF,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CA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,IAAI;QACJ,OAAO;QACP,YAAY;QACZ,eAAe;QACf,MAAM;QACN,eAAe;QACf,OAAO;KACR,CAAC,CAAA;IAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;AAClC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.test.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { sql } from '@livestore/common';
|
|
2
|
-
import { Schema } from '@livestore/utils/effect';
|
|
3
|
-
import { makeInMemoryAdapter } from '@livestore/web';
|
|
4
|
-
import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { unstable_batchedUpdates as batchUpdates } from 'react-dom';
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
8
|
-
import { schema, tables } from '../__tests__/react/fixture.js';
|
|
9
|
-
import { querySQL } from '../reactiveQueries/sql.js';
|
|
10
|
-
import * as LiveStoreReact from './index.js';
|
|
11
|
-
import { LiveStoreProvider } from './LiveStoreProvider.js';
|
|
12
|
-
describe('LiveStoreProvider', () => {
|
|
13
|
-
it('simple', async () => {
|
|
14
|
-
let appRenderCount = 0;
|
|
15
|
-
const allTodos$ = querySQL(`select * from todos`, { schema: Schema.Array(tables.todos.schema) });
|
|
16
|
-
const App = () => {
|
|
17
|
-
appRenderCount++;
|
|
18
|
-
const todos = LiveStoreReact.useQuery(allTodos$);
|
|
19
|
-
return React.createElement("div", null, JSON.stringify(todos));
|
|
20
|
-
};
|
|
21
|
-
const abortController = new AbortController();
|
|
22
|
-
const Root = ({ forceUpdate }) => {
|
|
23
|
-
const bootCb = React.useCallback((db) => db.execute(sql `INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
|
|
24
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
-
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
26
|
-
return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
|
|
27
|
-
"Loading LiveStore: ",
|
|
28
|
-
status.stage), adapter: adapterMemo, boot: bootCb, signal: abortController.signal, batchUpdates: batchUpdates },
|
|
29
|
-
React.createElement(App, null)));
|
|
30
|
-
};
|
|
31
|
-
const { rerender } = render(React.createElement(Root, { forceUpdate: 1 }));
|
|
32
|
-
expect(appRenderCount).toBe(0);
|
|
33
|
-
await waitForElementToBeRemoved(() => screen.getByText((_) => _.startsWith('Loading LiveStore')));
|
|
34
|
-
expect(appRenderCount).toBe(1);
|
|
35
|
-
rerender(React.createElement(Root, { forceUpdate: 2 }));
|
|
36
|
-
await waitFor(() => screen.getByText('Loading LiveStore: loading'));
|
|
37
|
-
await waitFor(() => screen.getByText((_) => _.includes('buy milk')));
|
|
38
|
-
expect(appRenderCount).toBe(2);
|
|
39
|
-
abortController.abort();
|
|
40
|
-
await waitFor(() => screen.getByText('LiveStore Shutdown due to abort signal'));
|
|
41
|
-
});
|
|
42
|
-
it('error during boot', async () => {
|
|
43
|
-
let appRenderCount = 0;
|
|
44
|
-
const App = () => {
|
|
45
|
-
appRenderCount++;
|
|
46
|
-
return React.createElement("div", null, "hello world");
|
|
47
|
-
};
|
|
48
|
-
const Root = ({ forceUpdate }) => {
|
|
49
|
-
const bootCb = React.useCallback((db) => db.execute(sql `INSERT INTO todos_mising_table (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
|
|
50
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
-
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
52
|
-
return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
|
|
53
|
-
"Loading LiveStore: ",
|
|
54
|
-
status.stage), adapter: adapterMemo, boot: bootCb, batchUpdates: batchUpdates },
|
|
55
|
-
React.createElement(App, null)));
|
|
56
|
-
};
|
|
57
|
-
render(React.createElement(Root, { forceUpdate: 1 }));
|
|
58
|
-
expect(appRenderCount).toBe(0);
|
|
59
|
-
await waitFor(() => screen.getByText((_) => _.startsWith('LiveStore.UnexpectedError')));
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
//# sourceMappingURL=LiveStoreProvider.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.test.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAC3F,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,uBAAuB,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtB,IAAI,cAAc,GAAG,CAAC,CAAA;QAEtB,MAAM,SAAS,GAAG,QAAQ,CAAC,qBAAqB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC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AAC,iBAAiB,IAChB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;;oBAAyB,MAAM,CAAC,KAAK,CAAO,EACvE,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY;gBAE1B,oBAAC,GAAG,OAAG,CACW,CACrB,CAAA;QACH,CAAC,CAAA;QAED,MAAM,CAAC,oBAAC,IAAI,IAAC,WAAW,EAAE,CAAC,GAAI,CAAC,CAAA;QAEhC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAE9B,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAA;IACzF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { LiveQuery } from '../../reactiveQueries/base-class.js';
|
|
3
|
-
export type LiveListProps<TItem> = {
|
|
4
|
-
items$: LiveQuery<ReadonlyArray<TItem>>;
|
|
5
|
-
renderItem: (item: TItem, opts: {
|
|
6
|
-
index: number;
|
|
7
|
-
isInitialListRender: boolean;
|
|
8
|
-
}) => React.ReactNode;
|
|
9
|
-
/** Needs to be unique across all list items */
|
|
10
|
-
getKey: (item: TItem, index: number) => string | number;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* This component is a helper component for rendering a list of items for a LiveQuery of an array of items.
|
|
14
|
-
* The idea is that instead of letting React handle the rendering of the items array directly,
|
|
15
|
-
* we derive a item LiveQuery for each item which moves the reactivity to the item level when a single item changes.
|
|
16
|
-
*
|
|
17
|
-
* In the future we want to make this component even more efficient by using incremental rendering (https://github.com/livestorejs/livestore/pull/55)
|
|
18
|
-
* e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
|
|
19
|
-
*/
|
|
20
|
-
export declare const LiveList: <TItem>({ items$, renderItem, getKey }: LiveListProps<TItem>) => React.ReactNode;
|
|
21
|
-
//# sourceMappingURL=LiveList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveList.d.ts","sourceRoot":"","sources":["../../../src/react/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAA;AAWpE,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI;IACjC,MAAM,EAAE,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAEvC,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAA;IACnG,+CAA+C;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;CACxD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,kCAAmC,aAAa,CAAC,KAAK,CAAC,KAAG,KAAK,CAAC,SA8B7F,CAAA"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { computed } from '../../reactiveQueries/js.js';
|
|
3
|
-
import { useQuery } from '../useQuery.js';
|
|
4
|
-
import { useTemporaryQuery } from '../useTemporaryQuery.js';
|
|
5
|
-
/**
|
|
6
|
-
* This component is a helper component for rendering a list of items for a LiveQuery of an array of items.
|
|
7
|
-
* The idea is that instead of letting React handle the rendering of the items array directly,
|
|
8
|
-
* we derive a item LiveQuery for each item which moves the reactivity to the item level when a single item changes.
|
|
9
|
-
*
|
|
10
|
-
* In the future we want to make this component even more efficient by using incremental rendering (https://github.com/livestorejs/livestore/pull/55)
|
|
11
|
-
* e.g. when an item is added/removed/moved to only re-render the affected DOM nodes.
|
|
12
|
-
*/
|
|
13
|
-
export const LiveList = ({ items$, renderItem, getKey }) => {
|
|
14
|
-
const [hasMounted, setHasMounted] = React.useState(false);
|
|
15
|
-
React.useEffect(() => setHasMounted(true), []);
|
|
16
|
-
const keysCb = React.useCallback(() => computed((get) => get(items$).map(getKey)), [getKey, items$]);
|
|
17
|
-
const keys = useTemporaryQuery(keysCb, 'fixed');
|
|
18
|
-
const arr = React.useMemo(() => keys.map((key) =>
|
|
19
|
-
// TODO figure out a way so that `item$` returns an ordered lookup map to more efficiently find the item by key
|
|
20
|
-
[key, computed((get) => get(items$).find((item) => getKey(item, 0) === key))]), [getKey, items$, keys]);
|
|
21
|
-
return (React.createElement(React.Fragment, null, arr.map(([key, item$], index) => (React.createElement(ItemWrapperMemo, { key: key, itemKey: key, "item$": item$, opts: { isInitialListRender: !hasMounted, index }, renderItem: renderItem })))));
|
|
22
|
-
};
|
|
23
|
-
const ItemWrapper = ({ item$, opts, renderItem, }) => {
|
|
24
|
-
const item = useQuery(item$);
|
|
25
|
-
return React.createElement(React.Fragment, null, renderItem(item, opts));
|
|
26
|
-
};
|
|
27
|
-
const ItemWrapperMemo = React.memo(ItemWrapper, (prev, next) => prev.itemKey === next.itemKey &&
|
|
28
|
-
prev.renderItem === prev.renderItem &&
|
|
29
|
-
prev.opts.index === next.opts.index &&
|
|
30
|
-
prev.opts.isInitialListRender === next.opts.isInitialListRender);
|
|
31
|
-
//# sourceMappingURL=LiveList.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LiveList.js","sourceRoot":"","sources":["../../../src/react/components/LiveList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MA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,EAAE,GAAG,WACL,KAAK,EACZ,IAAI,EAAE,EAAE,mBAAmB,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,EACjD,UAAU,EAAE,UAAU,GACtB,CACH,CAAC,CACD,CACJ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAS,EAC3B,KAAK,EACL,IAAI,EACJ,UAAU,GAMX,EAAE,EAAE;IACH,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE5B,OAAO,0CAAG,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAI,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAChC,WAAW,EACX,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACb,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;IAC7B,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;IACnC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK;IACnC,IAAI,CAAC,IAAI,CAAC,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAC5C,CAAA"}
|
package/dist/react/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { LiveStoreContext, useStore } from './LiveStoreContext.js';
|
|
2
|
-
export { LiveStoreProvider } from './LiveStoreProvider.js';
|
|
3
|
-
export { useQuery } from './useQuery.js';
|
|
4
|
-
export { useTemporaryQuery } from './useTemporaryQuery.js';
|
|
5
|
-
export { useStackInfo } from './utils/stack-info.js';
|
|
6
|
-
export { useRow, type StateSetters, type SetStateAction, type Dispatch, type UseRowResult as UseStateResult, } from './useRow.js';
|
|
7
|
-
export { useAtom } from './useAtom.js';
|
|
8
|
-
export { useLocalId, getLocalId } from './useLocalId.js';
|
|
9
|
-
export { LiveList, type LiveListProps } from './components/LiveList.js';
|
|
10
|
-
export type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,IAAI,cAAc,GACpC,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAGvE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA"}
|
package/dist/react/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { LiveStoreContext, useStore } from './LiveStoreContext.js';
|
|
2
|
-
export { LiveStoreProvider } from './LiveStoreProvider.js';
|
|
3
|
-
export { useQuery } from './useQuery.js';
|
|
4
|
-
export { useTemporaryQuery } from './useTemporaryQuery.js';
|
|
5
|
-
export { useStackInfo } from './utils/stack-info.js';
|
|
6
|
-
export { useRow, } from './useRow.js';
|
|
7
|
-
export { useAtom } from './useAtom.js';
|
|
8
|
-
export { useLocalId, getLocalId } from './useLocalId.js';
|
|
9
|
-
export { LiveList } from './components/LiveList.js';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,MAAM,GAKP,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAA"}
|
package/dist/react/useAtom.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type QueryInfoCol, type QueryInfoRow } from '@livestore/common';
|
|
2
|
-
import type { DbSchema } from '@livestore/common/schema';
|
|
3
|
-
import type { LiveQuery } from '../reactiveQueries/base-class.js';
|
|
4
|
-
import type { Dispatch, SetStateAction } from './useRow.js';
|
|
5
|
-
export declare const useAtom: <TQuery extends LiveQuery<any, QueryInfoRow<TTableDef> | QueryInfoCol<TTableDef, any>>, TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDefConstrained, boolean, DbSchema.TableOptions & {
|
|
6
|
-
deriveMutations: {
|
|
7
|
-
enabled: true;
|
|
8
|
-
};
|
|
9
|
-
}>>(query$: TQuery) => [value: TQuery["__result!"], setValue: Dispatch<SetStateAction<Partial<TQuery["__result!"]>>>];
|
|
10
|
-
//# sourceMappingURL=useAtom.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAtom.d.ts","sourceRoot":"","sources":["../../src/react/useAtom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAGjE,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3D,eAAO,MAAM,OAAO,GAClB,MAAM,SAAS,SAAS,CAAC,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,EACrF,SAAS,SAAS,QAAQ,CAAC,QAAQ,CACjC,QAAQ,CAAC,gCAAgC,EACzC,OAAO,EACP,QAAQ,CAAC,YAAY,GAAG;IAAE,eAAe,EAAE;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,CAAA;CAAE,CAC/D,UAEO,MAAM,KACb,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAoC/F,CAAA"}
|
package/dist/react/useAtom.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useStore } from './LiveStoreContext.js';
|
|
3
|
-
import { useQueryRef } from './useQuery.js';
|
|
4
|
-
export const useAtom = (query$) => {
|
|
5
|
-
const query$Ref = useQueryRef(query$);
|
|
6
|
-
const { store } = useStore();
|
|
7
|
-
// TODO make API equivalent to useRow
|
|
8
|
-
const setValue = React.useMemo(() => {
|
|
9
|
-
return (newValueOrFn) => {
|
|
10
|
-
const newValue = typeof newValueOrFn === 'function' ? newValueOrFn(query$Ref.current) : newValueOrFn;
|
|
11
|
-
if (query$.queryInfo._tag === 'Row') {
|
|
12
|
-
if (query$.queryInfo.table.options.isSingleton && query$.queryInfo.table.isSingleColumn) {
|
|
13
|
-
store.mutate(query$.queryInfo.table.update(newValue));
|
|
14
|
-
}
|
|
15
|
-
else if (query$.queryInfo.table.options.isSingleColumn) {
|
|
16
|
-
store.mutate(query$.queryInfo.table.update({ where: { id: query$.queryInfo.id }, values: { value: newValue } }));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
store.mutate(query$.queryInfo.table.update({ where: { id: query$.queryInfo.id }, values: newValue }));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
if (query$.queryInfo.table.options.isSingleton && query$.queryInfo.table.isSingleColumn) {
|
|
24
|
-
store.mutate(query$.queryInfo.table.update({ [query$.queryInfo.column]: newValue }));
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
store.mutate(query$.queryInfo.table.update({
|
|
28
|
-
where: { id: query$.queryInfo.id },
|
|
29
|
-
values: { [query$.queryInfo.column]: newValue },
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}, [query$.queryInfo, query$Ref, store]);
|
|
35
|
-
return [query$Ref.current, setValue];
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=useAtom.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAtom.js","sourceRoot":"","sources":["../../src/react/useAtom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,OAAO,GAAG,CAQrB,MAAc,EACkF,EAAE;IAClG,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAErC,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE5B,qCAAqC;IACrC,MAAM,QA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KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;gBACtF,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,MAAM,CACV,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;wBAC5B,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE;wBAClC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE;qBAChD,CAAC,CACH,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;IAExC,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;AACtC,CAAC,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type LocalIdOptions = {
|
|
2
|
-
key: string;
|
|
3
|
-
storageType: 'session' | 'local';
|
|
4
|
-
storageKeyPrefix: string;
|
|
5
|
-
makeId: () => string;
|
|
6
|
-
};
|
|
7
|
-
export declare const useLocalId: (opts?: Partial<LocalIdOptions>) => string;
|
|
8
|
-
export declare const getLocalId: (opts?: Partial<LocalIdOptions>) => string;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=useLocalId.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalId.d.ts","sourceRoot":"","sources":["../../src/react/useLocalId.ts"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,SAAS,GAAG,OAAO,CAAA;IAChC,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,MAAM,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,UAAU,UAAW,OAAO,CAAC,cAAc,CAAC,WAAkD,CAAA;AAE3G,eAAO,MAAM,UAAU,UAAW,OAAO,CAAC,cAAc,CAAC,WAoBxD,CAAA"}
|
package/dist/react/useLocalId.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { cuid } from '@livestore/utils/cuid';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export const useLocalId = (opts) => React.useMemo(() => getLocalId(opts), [opts]);
|
|
4
|
-
export const getLocalId = (opts) => {
|
|
5
|
-
// TODO find a better way to handle this
|
|
6
|
-
// Currently `getLocalId` gets imported and called in some worker-side code
|
|
7
|
-
// during development where Vite isn't tree-shaking yet.
|
|
8
|
-
if (typeof window === 'undefined' || window.localStorage === undefined || window.sessionStorage === undefined) {
|
|
9
|
-
return '';
|
|
10
|
-
}
|
|
11
|
-
const { key = '', storageType = 'session', storageKeyPrefix = 'livestore:localid:', makeId = cuid } = opts ?? {};
|
|
12
|
-
const storage = storageType === 'session' ? window.sessionStorage : window.localStorage;
|
|
13
|
-
const fullKey = `${storageKeyPrefix}:${key}`;
|
|
14
|
-
const storedKey = storage.getItem(fullKey);
|
|
15
|
-
if (storedKey)
|
|
16
|
-
return storedKey;
|
|
17
|
-
const newKey = makeId();
|
|
18
|
-
storage.setItem(fullKey, newKey);
|
|
19
|
-
return newKey;
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=useLocalId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalId.js","sourceRoot":"","sources":["../../src/react/useLocalId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AAE3G,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE;IAC3D,wCAAwC;IACxC,2EAA2E;IAC3E,wDAAwD;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QAC9G,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,WAAW,GAAG,SAAS,EAAE,gBAAgB,GAAG,oBAAoB,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;IAEhH,MAAM,OAAO,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAA;IACvF,MAAM,OAAO,GAAG,GAAG,gBAAgB,IAAI,GAAG,EAAE,CAAA;IAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE1C,IAAI,SAAS;QAAE,OAAO,SAAS,CAAA;IAE/B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA;IACvB,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAEhC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/dist/react/useQuery.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import type { GetResult, LiveQueryAny } from '../reactiveQueries/base-class.js';
|
|
4
|
-
export declare const useQuery: <TQuery extends LiveQueryAny>(query: TQuery) => GetResult<TQuery>;
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export declare const useQueryRef: <TQuery extends LiveQueryAny>(query$: TQuery, parentOtelContext?: otel.Context) => React.MutableRefObject<GetResult<TQuery>>;
|
|
9
|
-
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/react/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAiB/E,eAAO,MAAM,QAAQ,GAAI,MAAM,SAAS,YAAY,SAAS,MAAM,KAAG,SAAS,CAAC,MAAM,CAA+B,CAAA;AAErH;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,YAAY,UAC7C,MAAM,sBACM,IAAI,CAAC,OAAO,KAC/B,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,CA2E1C,CAAA"}
|
package/dist/react/useQuery.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { deepEqual } from '@livestore/utils';
|
|
2
|
-
import * as otel from '@opentelemetry/api';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { useStore } from './LiveStoreContext.js';
|
|
5
|
-
import { extractStackInfoFromStackTrace, originalStackLimit } from './utils/stack-info.js';
|
|
6
|
-
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
|
|
7
|
-
/**
|
|
8
|
-
* NOTE Some folks have suggested to use `React.useSyncExternalStore`, however, it's not doing anything special
|
|
9
|
-
* for what's needed here, so we handle everything manually.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* This is needed because the `React.useMemo` call below, can sometimes be called multiple times 🤷,
|
|
13
|
-
* so we need to "cache" the fact that we've already started a span for this component.
|
|
14
|
-
* The map entry is being removed again in the `React.useEffect` call below.
|
|
15
|
-
*/
|
|
16
|
-
const spanAlreadyStartedCache = new Map();
|
|
17
|
-
export const useQuery = (query) => useQueryRef(query).current;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export const useQueryRef = (query$, parentOtelContext) => {
|
|
22
|
-
const { store } = useStore();
|
|
23
|
-
React.useDebugValue(`LiveStore:useQuery:${query$.id}:${query$.label}`);
|
|
24
|
-
const stackInfo = React.useMemo(() => {
|
|
25
|
-
Error.stackTraceLimit = 10;
|
|
26
|
-
// eslint-disable-next-line unicorn/error-message
|
|
27
|
-
const stack = new Error().stack;
|
|
28
|
-
Error.stackTraceLimit = originalStackLimit;
|
|
29
|
-
return extractStackInfoFromStackTrace(stack);
|
|
30
|
-
}, []);
|
|
31
|
-
// The following `React.useMemo` and `React.useEffect` calls are used to start and end a span for the lifetime of this component.
|
|
32
|
-
const { span, otelContext } = React.useMemo(() => {
|
|
33
|
-
const existingSpan = spanAlreadyStartedCache.get(query$);
|
|
34
|
-
if (existingSpan !== undefined)
|
|
35
|
-
return existingSpan;
|
|
36
|
-
const span = store.otel.tracer.startSpan(`LiveStore:useQuery:${query$.label}`, { attributes: { label: query$.label, stackInfo: JSON.stringify(stackInfo) } }, parentOtelContext ?? store.otel.queriesSpanContext);
|
|
37
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
38
|
-
spanAlreadyStartedCache.set(query$, { span, otelContext });
|
|
39
|
-
return { span, otelContext };
|
|
40
|
-
}, [parentOtelContext, query$, stackInfo, store.otel.queriesSpanContext, store.otel.tracer]);
|
|
41
|
-
const initialResult = React.useMemo(() => query$.run(otelContext, {
|
|
42
|
-
_tag: 'react',
|
|
43
|
-
api: 'useQuery',
|
|
44
|
-
label: query$.label,
|
|
45
|
-
stackInfo,
|
|
46
|
-
}), [otelContext, query$, stackInfo]);
|
|
47
|
-
// We know the query has a result by the time we use it; so we can synchronously populate a default state
|
|
48
|
-
const [valueRef, setValue] = useStateRefWithReactiveInput(initialResult);
|
|
49
|
-
React.useEffect(() => () => {
|
|
50
|
-
spanAlreadyStartedCache.delete(query$);
|
|
51
|
-
span.end();
|
|
52
|
-
}, [query$, span]);
|
|
53
|
-
// Subscribe to future updates for this query
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
query$.activeSubscriptions.add(stackInfo);
|
|
56
|
-
return store.subscribe(query$, (newValue) => {
|
|
57
|
-
// NOTE: we return a reference to the result object within LiveStore;
|
|
58
|
-
// this implies that app code must not mutate the results, or else
|
|
59
|
-
// there may be weird reactivity bugs.
|
|
60
|
-
if (deepEqual(newValue, valueRef.current) === false) {
|
|
61
|
-
setValue(newValue);
|
|
62
|
-
}
|
|
63
|
-
}, () => {
|
|
64
|
-
query$.activeSubscriptions.delete(stackInfo);
|
|
65
|
-
}, { label: query$.label, otelContext });
|
|
66
|
-
}, [stackInfo, query$, setValue, store, valueRef, otelContext, span]);
|
|
67
|
-
return valueRef;
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=useQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../src/react/useQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAA;AAEtF;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAAgE,CAAA;AAEvG,MAAM,CAAC,MAAM,QAAQ,GAAG,CAA8B,KAAa,EAAqB,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,OAAO,CAAA;AAErH;;GAEG;AACH,M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AC,SAAS,CAAC,CAAA;QAC9C,CAAC,EACD,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,CACrC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;IAErE,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.test.d.ts","sourceRoot":"","sources":["../../src/react/useQuery.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from '@livestore/utils/effect';
|
|
2
|
-
import { renderHook } from '@testing-library/react';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { makeTodoMvc, tables, todos } from '../__tests__/react/fixture.js';
|
|
6
|
-
import { querySQL } from '../reactiveQueries/sql.js';
|
|
7
|
-
import * as LiveStoreReact from './index.js';
|
|
8
|
-
describe('useQuery', () => {
|
|
9
|
-
it('simple', () => Effect.gen(function* () {
|
|
10
|
-
const { wrapper, store, makeRenderCount } = yield* makeTodoMvc();
|
|
11
|
-
const renderCount = makeRenderCount();
|
|
12
|
-
const allTodos$ = querySQL(`select * from todos`, { schema: Schema.Array(tables.todos.schema) });
|
|
13
|
-
const { result } = renderHook(() => {
|
|
14
|
-
renderCount.inc();
|
|
15
|
-
return LiveStoreReact.useQuery(allTodos$);
|
|
16
|
-
}, { wrapper });
|
|
17
|
-
expect(result.current.length).toBe(0);
|
|
18
|
-
expect(renderCount.val).toBe(1);
|
|
19
|
-
React.act(() => store.mutate(todos.insert({ id: 't1', text: 'buy milk', completed: false })));
|
|
20
|
-
expect(result.current.length).toBe(1);
|
|
21
|
-
expect(result.current[0].text).toBe('buy milk');
|
|
22
|
-
expect(renderCount.val).toBe(2);
|
|
23
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
24
|
-
it('same `useQuery` hook invoked with different queries', () => Effect.gen(function* () {
|
|
25
|
-
const { wrapper, store, makeRenderCount } = yield* makeTodoMvc();
|
|
26
|
-
const renderCount = makeRenderCount();
|
|
27
|
-
const todo1$ = querySQL(`select * from todos where id = 't1'`, {
|
|
28
|
-
label: 'libraryTracksView1',
|
|
29
|
-
schema: Schema.Array(tables.todos.schema),
|
|
30
|
-
});
|
|
31
|
-
const todo2$ = querySQL(`select * from todos where id = 't2'`, {
|
|
32
|
-
label: 'libraryTracksView2',
|
|
33
|
-
schema: Schema.Array(tables.todos.schema),
|
|
34
|
-
});
|
|
35
|
-
store.mutate(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy eggs', completed: false }));
|
|
36
|
-
const { result, rerender } = renderHook((todoId) => {
|
|
37
|
-
renderCount.inc();
|
|
38
|
-
const query$ = React.useMemo(() => (todoId === 't1' ? todo1$ : todo2$), [todoId]);
|
|
39
|
-
return LiveStoreReact.useQuery(query$)[0].text;
|
|
40
|
-
}, { wrapper, initialProps: 't1' });
|
|
41
|
-
expect(result.current).toBe('buy milk');
|
|
42
|
-
expect(renderCount.val).toBe(1);
|
|
43
|
-
React.act(() => store.mutate(todos.update({ where: { id: 't1' }, values: { text: 'buy soy milk' } })));
|
|
44
|
-
expect(result.current).toBe('buy soy milk');
|
|
45
|
-
expect(renderCount.val).toBe(2);
|
|
46
|
-
rerender('t2');
|
|
47
|
-
expect(result.current).toBe('buy eggs');
|
|
48
|
-
expect(renderCount.val).toBe(3);
|
|
49
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=useQuery.test.js.map
|