@livestore/livestore 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -28
- package/dist/.tsbuildinfo +1 -0
- package/dist/QueryCache.d.ts +20 -0
- package/dist/QueryCache.d.ts.map +1 -0
- package/dist/QueryCache.js +71 -0
- package/dist/QueryCache.js.map +1 -0
- package/dist/__tests__/react/fixture.d.ts +26 -0
- package/dist/__tests__/react/fixture.d.ts.map +1 -0
- package/dist/__tests__/react/fixture.js +60 -0
- package/dist/__tests__/react/fixture.js.map +1 -0
- package/dist/__tests__/react/useComponentState.test.d.ts +2 -0
- package/dist/__tests__/react/useComponentState.test.d.ts.map +1 -0
- package/dist/__tests__/react/useComponentState.test.js +68 -0
- package/dist/__tests__/react/useComponentState.test.js.map +1 -0
- package/dist/__tests__/react/useLQuery.test.d.ts +2 -0
- package/dist/__tests__/react/useLQuery.test.d.ts.map +1 -0
- package/dist/__tests__/react/useLQuery.test.js +38 -0
- package/dist/__tests__/react/useLQuery.test.js.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +2 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js +73 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js.map +1 -0
- package/dist/__tests__/react/useQuery.test.d.ts +2 -0
- package/dist/__tests__/react/useQuery.test.d.ts.map +1 -0
- package/dist/__tests__/react/useQuery.test.js +33 -0
- package/dist/__tests__/react/useQuery.test.js.map +1 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts +2 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts.map +1 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js +38 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js.map +1 -0
- package/dist/__tests__/reactive.test.d.ts +2 -0
- package/dist/__tests__/reactive.test.d.ts.map +1 -0
- package/dist/__tests__/reactive.test.js +271 -0
- package/dist/__tests__/reactive.test.js.map +1 -0
- package/dist/__tests__/reactiveQueries/sql.test.d.ts +2 -0
- package/dist/__tests__/reactiveQueries/sql.test.d.ts.map +1 -0
- package/dist/__tests__/reactiveQueries/sql.test.js +337 -0
- package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -0
- package/dist/bounded-collections.d.ts +34 -0
- package/dist/bounded-collections.d.ts.map +1 -0
- package/dist/bounded-collections.js +103 -0
- package/dist/bounded-collections.js.map +1 -0
- package/dist/componentKey.d.ts +20 -0
- package/dist/componentKey.d.ts.map +1 -0
- package/dist/componentKey.js +3 -0
- package/dist/componentKey.js.map +1 -0
- package/dist/effect/LiveStore.d.ts +36 -0
- package/dist/effect/LiveStore.d.ts.map +1 -0
- package/dist/effect/LiveStore.js +41 -0
- package/dist/effect/LiveStore.js.map +1 -0
- package/dist/effect/index.d.ts +2 -0
- package/dist/effect/index.d.ts.map +1 -0
- package/dist/effect/index.js +2 -0
- package/dist/effect/index.js.map +1 -0
- package/dist/events.d.ts +7 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/inMemoryDatabase.d.ts +56 -0
- package/dist/inMemoryDatabase.d.ts.map +1 -0
- package/dist/inMemoryDatabase.js +223 -0
- package/dist/inMemoryDatabase.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.d.ts +16 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +67 -0
- package/dist/migrations.js.map +1 -0
- package/dist/otel.d.ts +4 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +6 -0
- package/dist/otel.js.map +1 -0
- package/dist/react/LiveStoreContext.d.ts +11 -0
- package/dist/react/LiveStoreContext.d.ts.map +1 -0
- package/dist/react/LiveStoreContext.js +10 -0
- package/dist/react/LiveStoreContext.js.map +1 -0
- package/dist/react/LiveStoreProvider.d.ts +20 -0
- package/dist/react/LiveStoreProvider.d.ts.map +1 -0
- package/dist/react/LiveStoreProvider.js +52 -0
- package/dist/react/LiveStoreProvider.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useComponentState.d.ts +50 -0
- package/dist/react/useComponentState.d.ts.map +1 -0
- package/dist/react/useComponentState.js +248 -0
- package/dist/react/useComponentState.js.map +1 -0
- package/dist/react/useGlobalQuery.d.ts +3 -0
- package/dist/react/useGlobalQuery.d.ts.map +1 -0
- package/dist/react/useGlobalQuery.js +26 -0
- package/dist/react/useGlobalQuery.js.map +1 -0
- package/dist/react/useGraphQL.d.ts +13 -0
- package/dist/react/useGraphQL.d.ts.map +1 -0
- package/dist/react/useGraphQL.js +87 -0
- package/dist/react/useGraphQL.js.map +1 -0
- package/dist/react/useLiveStoreComponent.d.ts +75 -0
- package/dist/react/useLiveStoreComponent.d.ts.map +1 -0
- package/dist/react/useLiveStoreComponent.js +361 -0
- package/dist/react/useLiveStoreComponent.js.map +1 -0
- package/dist/react/useQuery.d.ts +3 -0
- package/dist/react/useQuery.d.ts.map +1 -0
- package/dist/react/useQuery.js +42 -0
- package/dist/react/useQuery.js.map +1 -0
- package/dist/react/useTemporaryQuery.d.ts +8 -0
- package/dist/react/useTemporaryQuery.d.ts.map +1 -0
- package/dist/react/useTemporaryQuery.js +17 -0
- package/dist/react/useTemporaryQuery.js.map +1 -0
- package/dist/react/utils/extractNamesFromStackTrace.d.ts +3 -0
- package/dist/react/utils/extractNamesFromStackTrace.d.ts.map +1 -0
- package/dist/react/utils/extractNamesFromStackTrace.js +40 -0
- package/dist/react/utils/extractNamesFromStackTrace.js.map +1 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts +7 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts.map +1 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.js +40 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.js.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +13 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js +38 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +1 -0
- package/dist/reactive.d.ts +134 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +409 -0
- package/dist/reactive.js.map +1 -0
- package/dist/reactiveQueries/base-class.d.ts +32 -0
- package/dist/reactiveQueries/base-class.d.ts.map +1 -0
- package/dist/reactiveQueries/base-class.js +30 -0
- package/dist/reactiveQueries/base-class.js.map +1 -0
- package/dist/reactiveQueries/graph.d.ts +10 -0
- package/dist/reactiveQueries/graph.d.ts.map +1 -0
- package/dist/reactiveQueries/graph.js +6 -0
- package/dist/reactiveQueries/graph.js.map +1 -0
- package/dist/reactiveQueries/graphql.d.ts +42 -0
- package/dist/reactiveQueries/graphql.d.ts.map +1 -0
- package/dist/reactiveQueries/graphql.js +99 -0
- package/dist/reactiveQueries/graphql.js.map +1 -0
- package/dist/reactiveQueries/js.d.ts +23 -0
- package/dist/reactiveQueries/js.d.ts.map +1 -0
- package/dist/reactiveQueries/js.js +36 -0
- package/dist/reactiveQueries/js.js.map +1 -0
- package/dist/reactiveQueries/sql.d.ts +35 -0
- package/dist/reactiveQueries/sql.d.ts.map +1 -0
- package/dist/reactiveQueries/sql.js +97 -0
- package/dist/reactiveQueries/sql.js.map +1 -0
- package/dist/schema.d.ts +81 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +46 -0
- package/dist/schema.js.map +1 -0
- package/dist/storage/in-memory/index.d.ts +15 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -0
- package/dist/storage/in-memory/index.js +14 -0
- package/dist/storage/in-memory/index.js.map +1 -0
- package/dist/storage/index.d.ts +14 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/tauri/index.d.ts +19 -0
- package/dist/storage/tauri/index.d.ts.map +1 -0
- package/dist/storage/tauri/index.js +38 -0
- package/dist/storage/tauri/index.js.map +1 -0
- package/dist/storage/utils/idb.d.ts +10 -0
- package/dist/storage/utils/idb.d.ts.map +1 -0
- package/dist/storage/utils/idb.js +58 -0
- package/dist/storage/utils/idb.js.map +1 -0
- package/dist/storage/web-worker/index.d.ts +27 -0
- package/dist/storage/web-worker/index.d.ts.map +1 -0
- package/dist/storage/web-worker/index.js +74 -0
- package/dist/storage/web-worker/index.js.map +1 -0
- package/dist/storage/web-worker/worker.d.ts +13 -0
- package/dist/storage/web-worker/worker.d.ts.map +1 -0
- package/dist/storage/web-worker/worker.js +110 -0
- package/dist/storage/web-worker/worker.js.map +1 -0
- package/dist/store.d.ts +159 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +626 -0
- package/dist/store.js.map +1 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +55 -0
- package/dist/util.js.map +1 -0
- package/package.json +47 -19
- package/src/QueryCache.ts +1 -1
- package/src/__tests__/react/fixture.tsx +35 -39
- package/src/__tests__/react/{useLiveStoreComponent.test.tsx → useComponentState.test.tsx} +9 -20
- package/src/__tests__/react/useQuery.test.tsx +48 -0
- package/src/__tests__/react/utils/extractStackInfoFromStackTrace.test.ts +40 -0
- package/src/__tests__/reactive.test.ts +194 -142
- package/src/__tests__/reactiveQueries/sql.test.ts +372 -0
- package/src/effect/LiveStore.ts +22 -31
- package/src/events.ts +1 -1
- package/src/inMemoryDatabase.ts +117 -142
- package/src/index.ts +18 -22
- package/src/migrations.ts +119 -0
- package/src/otel.ts +0 -11
- package/src/react/LiveStoreProvider.tsx +24 -23
- package/src/react/index.ts +12 -7
- package/src/react/useComponentState.ts +409 -0
- package/src/react/useQuery.ts +58 -0
- package/src/react/useTemporaryQuery.ts +21 -0
- package/src/react/utils/extractStackInfoFromStackTrace.ts +47 -0
- package/src/reactive.ts +386 -267
- package/src/reactiveQueries/base-class.ts +61 -39
- package/src/reactiveQueries/graph.ts +15 -0
- package/src/reactiveQueries/graphql.ts +147 -31
- package/src/reactiveQueries/js.ts +54 -21
- package/src/reactiveQueries/sql.ts +128 -37
- package/src/schema.ts +69 -145
- package/src/storage/in-memory/index.ts +21 -0
- package/src/storage/index.ts +27 -0
- package/src/{backends/tauri.ts → storage/tauri/index.ts} +14 -28
- package/src/storage/web-worker/index.ts +116 -0
- package/src/{backends/web-worker.ts → storage/web-worker/worker.ts} +17 -52
- package/src/store.ts +466 -457
- package/src/util.ts +13 -3
- package/tsconfig.json +1 -3
- package/src/backends/base.ts +0 -67
- package/src/backends/index.ts +0 -98
- package/src/backends/noop.ts +0 -32
- package/src/backends/web-in-memory.ts +0 -65
- package/src/backends/web.ts +0 -97
- package/src/react/useGlobalQuery.ts +0 -40
- package/src/react/useGraphQL.ts +0 -112
- package/src/react/useLiveStoreComponent.ts +0 -483
- /package/src/{backends → storage}/utils/idb.ts +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useStore } from './LiveStoreContext.js';
|
|
4
|
+
import { extractStackInfoFromStackTrace, originalStackLimit } from './utils/extractStackInfoFromStackTrace.js';
|
|
5
|
+
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
|
|
6
|
+
export const useQuery = (query) => {
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
// TODO proper otel context
|
|
9
|
+
const initialResult = React.useMemo(() => query.run(), [query]);
|
|
10
|
+
// We know the query has a result by the time we use it; so we can synchronously populate a default state
|
|
11
|
+
const [valueRef, setValue] = useStateRefWithReactiveInput(initialResult);
|
|
12
|
+
const subscriptionInfo = React.useMemo(() => {
|
|
13
|
+
Error.stackTraceLimit = 10;
|
|
14
|
+
// eslint-disable-next-line unicorn/error-message
|
|
15
|
+
const stack = new Error().stack;
|
|
16
|
+
Error.stackTraceLimit = originalStackLimit;
|
|
17
|
+
return { stack: extractStackInfoFromStackTrace(stack) };
|
|
18
|
+
}, []);
|
|
19
|
+
// Subscribe to future updates for this query
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
return store.otel.tracer.startActiveSpan(`LiveStore:useQuery:${query.label}`,
|
|
22
|
+
// `LiveStore:useQuery:${labelForKey(query.componentKey)}:${query.label}`,
|
|
23
|
+
{ attributes: { label: query.label } }, store.otel.queriesSpanContext, (span) => {
|
|
24
|
+
query.activeSubscriptions.add(subscriptionInfo);
|
|
25
|
+
const unsub = store.subscribe(query, (v) => {
|
|
26
|
+
// NOTE: we return a reference to the result object within LiveStore;
|
|
27
|
+
// this implies that app code must not mutate the results, or else
|
|
28
|
+
// there may be weird reactivity bugs.
|
|
29
|
+
if (isEqual(v, valueRef.current) === false) {
|
|
30
|
+
setValue(v);
|
|
31
|
+
}
|
|
32
|
+
}, undefined, { label: query.label });
|
|
33
|
+
return () => {
|
|
34
|
+
query.activeSubscriptions.delete(subscriptionInfo);
|
|
35
|
+
unsub();
|
|
36
|
+
span.end();
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}, [subscriptionInfo, query, setValue, store, valueRef]);
|
|
40
|
+
return valueRef.current;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../src/react/useQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9G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gBAClE,sCAAsC;gBACtC,IAAI,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,KAAK,EAAE;oBAC1C,QAAQ,CAAC,CAAC,CAAC,CAAA;iBACZ;YACH,CAAC,EACD,SAAS,EACT,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CACvB,CAAA;YACD,OAAO,GAAG,EAAE;gBACV,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;gBAClD,KAAK,EAAE,CAAA;gBACP,IAAI,CAAC,GAAG,EAAE,CAAA;YACZ,CAAC,CAAA;QACH,CAAC,CACF,CAAA;IACH,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;IAExD,OAAO,QAAQ,CAAC,OAAO,CAAA;AACzB,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ILiveStoreQuery } from '../reactiveQueries/base-class.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
4
|
+
*
|
|
5
|
+
* Make sure `makeQuery` is a memoized function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useTemporaryQuery: <TResult>(makeQuery: () => ILiveStoreQuery<TResult>) => TResult;
|
|
8
|
+
//# sourceMappingURL=useTemporaryQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemporaryQuery.d.ts","sourceRoot":"","sources":["../../src/react/useTemporaryQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAGvE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,iEAU7B,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useQuery } from './useQuery.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
5
|
+
*
|
|
6
|
+
* Make sure `makeQuery` is a memoized function.
|
|
7
|
+
*/
|
|
8
|
+
export const useTemporaryQuery = (makeQuery) => {
|
|
9
|
+
const query = React.useMemo(() => makeQuery(), [makeQuery]);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
return () => {
|
|
12
|
+
query.destroy();
|
|
13
|
+
};
|
|
14
|
+
}, [query]);
|
|
15
|
+
return useQuery(query);
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useTemporaryQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemporaryQuery.js","sourceRoot":"","sources":["../../src/react/useTemporaryQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAU,SAAyC,EAAW,EAAE;IAC/F,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAE3D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,OAAO,GAAG,EAAE;YACV,KAAK,CAAC,OAAO,EAAE,CAAA;QACjB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractNamesFromStackTrace.d.ts","sourceRoot":"","sources":["../../../src/react/utils/extractNamesFromStackTrace.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAqBvD,eAAO,MAAM,0BAA0B,eAAgB,MAAM,KAAG,MAAM,EAoBrE,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const originalStackLimit = Error.stackTraceLimit;
|
|
2
|
+
/*
|
|
3
|
+
Example stack trace:
|
|
4
|
+
|
|
5
|
+
Error
|
|
6
|
+
at https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:18:23
|
|
7
|
+
at mountMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12817:27)
|
|
8
|
+
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:13141:24)
|
|
9
|
+
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-4WADDZ2G.js?v=3eb66ed6:1094:29)
|
|
10
|
+
at useQuery (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:13:33)
|
|
11
|
+
at useAppState (https://localhost:8081/src/db/AppState.ts?t=1699550216884:17:34)
|
|
12
|
+
at useRoute (https://localhost:8081/src/db/AppState.ts?t=1699550216884:74:22)
|
|
13
|
+
at RouteLink (https://localhost:8081/src/components/Link.tsx?t=1699550216884:36:7)
|
|
14
|
+
at renderWithHooks (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12171:26)
|
|
15
|
+
at mountIndeterminateComponent (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:14921:21)
|
|
16
|
+
|
|
17
|
+
Approach:
|
|
18
|
+
- Start filtering at `at useQuery` (including)
|
|
19
|
+
- Stop filtering at `at renderWithHooks` (excluding)
|
|
20
|
+
*/
|
|
21
|
+
export const extractNamesFromStackTrace = (stackTrace) => {
|
|
22
|
+
const namePattern = / at (\w+)/g;
|
|
23
|
+
let match;
|
|
24
|
+
const names = [];
|
|
25
|
+
let hasReachedStart = false;
|
|
26
|
+
while ((match = namePattern.exec(stackTrace)) !== null) {
|
|
27
|
+
if (match[1]?.startsWith('use')) {
|
|
28
|
+
hasReachedStart = true;
|
|
29
|
+
// match[1] contains the captured group, which is the name we want to extract
|
|
30
|
+
names.unshift(match[1]);
|
|
31
|
+
}
|
|
32
|
+
else if (hasReachedStart) {
|
|
33
|
+
// We've reached the end of the `use*` functions, so we're adding the component name and stop
|
|
34
|
+
names.unshift(match[1]);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return names;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=extractNamesFromStackTrace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractNamesFromStackTrace.js","sourceRoot":"","sources":["../../../src/react/utils/extractNamesFromStackTrace.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAEvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,UAAkB,EAAY,EAAE;IACzE,MAAM,WAAW,GAAG,YAAY,CAAA;IAChC,IAAI,KAA6B,CAAA;IACjC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,IAAI,EAAE;QACtD,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE;YAC/B,eAAe,GAAG,IAAI,CAAA;YAEtB,6EAA6E;YAC7E,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;SACxB;aAAM,IAAI,eAAe,EAAE;YAC1B,6FAA6F;YAC7F,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAA;YACxB,MAAK;SACN;KACF;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const originalStackLimit: number;
|
|
2
|
+
export type StackInfo = {
|
|
3
|
+
name: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const extractStackInfoFromStackTrace: (stackTrace: string) => StackInfo[];
|
|
7
|
+
//# sourceMappingURL=extractStackInfoFromStackTrace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractStackInfoFromStackTrace.d.ts","sourceRoot":"","sources":["../../../src/react/utils/extractStackInfoFromStackTrace.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAEvD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqBD,eAAO,MAAM,8BAA8B,eAAgB,MAAM,KAAG,SAAS,EAoB5E,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const originalStackLimit = Error.stackTraceLimit;
|
|
2
|
+
/*
|
|
3
|
+
Example stack trace:
|
|
4
|
+
|
|
5
|
+
Error
|
|
6
|
+
at https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:18:23
|
|
7
|
+
at mountMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12817:27)
|
|
8
|
+
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:13141:24)
|
|
9
|
+
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-4WADDZ2G.js?v=3eb66ed6:1094:29)
|
|
10
|
+
at useQuery (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:13:33)
|
|
11
|
+
at useAppState (https://localhost:8081/src/db/AppState.ts?t=1699550216884:17:34)
|
|
12
|
+
at useRoute (https://localhost:8081/src/db/AppState.ts?t=1699550216884:74:22)
|
|
13
|
+
at RouteLink (https://localhost:8081/src/components/Link.tsx?t=1699550216884:36:7)
|
|
14
|
+
at renderWithHooks (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12171:26)
|
|
15
|
+
at mountIndeterminateComponent (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:14921:21)
|
|
16
|
+
|
|
17
|
+
Approach:
|
|
18
|
+
- Start filtering at `at useQuery` (including)
|
|
19
|
+
- Stop filtering at `at renderWithHooks` (excluding)
|
|
20
|
+
*/
|
|
21
|
+
export const extractStackInfoFromStackTrace = (stackTrace) => {
|
|
22
|
+
const namePattern = /at (\S+) \((.+)\)/g;
|
|
23
|
+
let match;
|
|
24
|
+
const stackInfoArr = [];
|
|
25
|
+
let hasReachedStart = false;
|
|
26
|
+
while ((match = namePattern.exec(stackTrace)) !== null) {
|
|
27
|
+
const [, name, filePath] = match;
|
|
28
|
+
if (name.startsWith('use')) {
|
|
29
|
+
hasReachedStart = true;
|
|
30
|
+
stackInfoArr.unshift({ name, filePath });
|
|
31
|
+
}
|
|
32
|
+
else if (hasReachedStart) {
|
|
33
|
+
// We've reached the end of the `use*` functions, so we're adding the component name and stop
|
|
34
|
+
stackInfoArr.unshift({ name, filePath });
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return stackInfoArr;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=extractStackInfoFromStackTrace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractStackInfoFromStackTrace.js","sourceRoot":"","sources":["../../../src/react/utils/extractStackInfoFromStackTrace.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAOvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,UAAkB,EAAe,EAAE;IAChF,MAAM,WAAW,GAAG,oBAAoB,CAAA;IACxC,IAAI,KAA6B,CAAA;IACjC,MAAM,YAAY,GAAgB,EAAE,CAAA;IACpC,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,IAAI,EAAE;QACtD,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,KAAwC,CAAA;QACnE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC1B,eAAe,GAAG,IAAI,CAAA;YAEtB,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;SACzC;aAAM,IAAI,eAAe,EAAE;YAC1B,6FAA6F;YAC7F,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YACxC,MAAK;SACN;KACF;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A variant of `React.useState` which allows the `inputState` to change over time as well.
|
|
4
|
+
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
|
|
5
|
+
*
|
|
6
|
+
* Notes:
|
|
7
|
+
* - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
|
|
8
|
+
* - This hook might not work properly with React Suspense
|
|
9
|
+
* - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare const useStateRefWithReactiveInput: <T>(inputState: T) => [React.MutableRefObject<T>, (newState: T | ((prev: T) => T)) => void];
|
|
13
|
+
//# sourceMappingURL=useStateRefWithReactiveInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStateRefWithReactiveInput.d.ts","sourceRoot":"","sources":["../../../src/react/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,wFAE0B,IAAI,CAwBtE,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A variant of `React.useState` which allows the `inputState` to change over time as well.
|
|
4
|
+
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
|
|
5
|
+
*
|
|
6
|
+
* Notes:
|
|
7
|
+
* - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
|
|
8
|
+
* - This hook might not work properly with React Suspense
|
|
9
|
+
* - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export const useStateRefWithReactiveInput = (inputState) => {
|
|
13
|
+
const [_, rerender] = React.useState(0);
|
|
14
|
+
const lastKnownInputStateRef = React.useRef(inputState);
|
|
15
|
+
const stateRef = React.useRef(inputState);
|
|
16
|
+
if (lastKnownInputStateRef.current !== inputState) {
|
|
17
|
+
lastKnownInputStateRef.current = inputState;
|
|
18
|
+
// NOTE we don't need to re-render here, because the component is already re-rendering due to the `inputState` change
|
|
19
|
+
stateRef.current = inputState;
|
|
20
|
+
}
|
|
21
|
+
const setStateAndRerender = React.useCallback((newState) => {
|
|
22
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/37663
|
|
23
|
+
const val = typeof newState === 'function' ? newState(stateRef.current) : newState;
|
|
24
|
+
stateRef.current = val;
|
|
25
|
+
rerender((c) => c + 1);
|
|
26
|
+
}, [rerender]);
|
|
27
|
+
return [stateRef, setStateAndRerender];
|
|
28
|
+
};
|
|
29
|
+
// Down-side of this implementation: Double render pass due to `setState` call (which forces a re-render)
|
|
30
|
+
// Keeping around for now in case `useStateRefWithReactiveInput` doesn't work out
|
|
31
|
+
// const _useStateWithReactiveInput = <T>(inputState: T): [T, (newState: T | ((prev: T) => T)) => void] => {
|
|
32
|
+
// const [externalState, setExternalState] = React.useState(inputState)
|
|
33
|
+
// if (externalState !== inputState) {
|
|
34
|
+
// setExternalState(inputState)
|
|
35
|
+
// }
|
|
36
|
+
// return [externalState, setExternalState]
|
|
37
|
+
// }
|
|
38
|
+
//# sourceMappingURL=useStateRefWithReactiveInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStateRefWithReactiveInput.js","sourceRoot":"","sources":["../../../src/react/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAa,EAC0D,EAAE;IACzE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEvC,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAE5C,IAAI,sBAAsB,CAAC,OAAO,KAAK,UAAU,EAAE;QACjD,sBAAsB,CAAC,OAAO,GAAG,UAAU,CAAA;QAE3C,qHAAqH;QACrH,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAA;KAC9B;IAED,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAC3C,CAAC,QAA8B,EAAE,EAAE;QACjC,wEAAwE;QACxE,MAAM,GAAG,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QAClF,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAA;QACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAA;IAED,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;AACxC,CAAC,CAAA;AAED,yGAAyG;AACzG,iFAAiF;AACjF,4GAA4G;AAC5G,yEAAyE;AAEzE,wCAAwC;AACxC,mCAAmC;AACnC,MAAM;AAEN,6CAA6C;AAC7C,IAAI"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { PrettifyFlat } from '@livestore/utils';
|
|
2
|
+
import type * as otel from '@opentelemetry/api';
|
|
3
|
+
import { BoundArray } from './bounded-collections.js';
|
|
4
|
+
export declare const NOT_REFRESHED_YET: unique symbol;
|
|
5
|
+
export type NOT_REFRESHED_YET = typeof NOT_REFRESHED_YET;
|
|
6
|
+
export type GetAtom = <T>(atom: Atom<T, any>, otelContext?: otel.Context) => T;
|
|
7
|
+
export type Ref<T> = {
|
|
8
|
+
_tag: 'ref';
|
|
9
|
+
id: string;
|
|
10
|
+
isDirty: false;
|
|
11
|
+
previousResult: T;
|
|
12
|
+
height: 0;
|
|
13
|
+
computeResult: () => T;
|
|
14
|
+
sub: Set<Atom<any, TODO>>;
|
|
15
|
+
super: Set<Atom<any, TODO> | Effect>;
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Container for meta information (e.g. the LiveStore Store) */
|
|
18
|
+
meta?: any;
|
|
19
|
+
equal: (a: T, b: T) => boolean;
|
|
20
|
+
};
|
|
21
|
+
type BaseThunk<TResult, TContext> = {
|
|
22
|
+
_tag: 'thunk';
|
|
23
|
+
id: string;
|
|
24
|
+
isDirty: boolean;
|
|
25
|
+
height: number;
|
|
26
|
+
computeResult: (otelContext?: otel.Context) => TResult;
|
|
27
|
+
previousResult: TResult | NOT_REFRESHED_YET;
|
|
28
|
+
sub: Set<Atom<any, TContext>>;
|
|
29
|
+
super: Set<Atom<any, TContext> | Effect>;
|
|
30
|
+
label?: string;
|
|
31
|
+
/** Container for meta information (e.g. the LiveStore Store) */
|
|
32
|
+
meta?: any;
|
|
33
|
+
equal: (a: TResult, b: TResult) => boolean;
|
|
34
|
+
recomputations: number;
|
|
35
|
+
__getResult: any;
|
|
36
|
+
};
|
|
37
|
+
export type Thunk<T, TContext> = BaseThunk<T, TContext>;
|
|
38
|
+
export type Atom<T, TContext> = Ref<T> | Thunk<T, TContext>;
|
|
39
|
+
export type Effect = {
|
|
40
|
+
_tag: 'effect';
|
|
41
|
+
id: string;
|
|
42
|
+
doEffect: (otelContext?: otel.Context) => void;
|
|
43
|
+
sub: Set<Atom<any, TODO>>;
|
|
44
|
+
};
|
|
45
|
+
export type Taggable<T extends string = string> = {
|
|
46
|
+
_tag: T;
|
|
47
|
+
};
|
|
48
|
+
export type ReactiveGraphOptions = {
|
|
49
|
+
effectsWrapper?: (runEffects: () => void) => void;
|
|
50
|
+
};
|
|
51
|
+
export type AtomDebugInfo<TDebugThunkInfo extends Taggable> = {
|
|
52
|
+
atom: SerializedAtom;
|
|
53
|
+
resultChanged: boolean;
|
|
54
|
+
durationMs: number;
|
|
55
|
+
debugInfo: TDebugThunkInfo;
|
|
56
|
+
};
|
|
57
|
+
export type RefreshDebugInfo<TDebugRefreshReason extends Taggable, TDebugThunkInfo extends Taggable> = {
|
|
58
|
+
/** Currently only used for easier handling in React (e.g. as key) */
|
|
59
|
+
id: string;
|
|
60
|
+
reason: TDebugRefreshReason;
|
|
61
|
+
refreshedAtoms: AtomDebugInfo<TDebugThunkInfo>[];
|
|
62
|
+
skippedRefresh: boolean;
|
|
63
|
+
durationMs: number;
|
|
64
|
+
/** Note we're using a regular `Date.now()` timestamp here as it's faster to produce and we don't need the fine accuracy */
|
|
65
|
+
completedTimestamp: number;
|
|
66
|
+
graphSnapshot: ReactiveGraphSnapshot;
|
|
67
|
+
};
|
|
68
|
+
export type RefreshReasonWithGenericReasons<T extends Taggable> = T | {
|
|
69
|
+
_tag: 'makeThunk';
|
|
70
|
+
label?: string;
|
|
71
|
+
} | {
|
|
72
|
+
_tag: 'makeEffect';
|
|
73
|
+
label?: string;
|
|
74
|
+
} | {
|
|
75
|
+
_tag: 'unknown';
|
|
76
|
+
};
|
|
77
|
+
export declare const unknownRefreshReason: () => {
|
|
78
|
+
_tag: "unknown";
|
|
79
|
+
};
|
|
80
|
+
export type SerializedAtom = Readonly<PrettifyFlat<Pick<Atom<unknown, TODO>, '_tag' | 'height' | 'id' | 'label' | 'meta'> & {
|
|
81
|
+
sub: string[];
|
|
82
|
+
super: string[];
|
|
83
|
+
}>>;
|
|
84
|
+
export type SerializedEffect = Readonly<PrettifyFlat<Pick<Effect, '_tag' | 'id'>>>;
|
|
85
|
+
type ReactiveGraphSnapshot = {
|
|
86
|
+
readonly atoms: SerializedAtom[];
|
|
87
|
+
};
|
|
88
|
+
export declare class ReactiveGraph<TDebugRefreshReason extends Taggable, TDebugThunkInfo extends Taggable, TContext = {}> {
|
|
89
|
+
readonly atoms: Set<Atom<any, TContext>>;
|
|
90
|
+
effectsWrapper: (runEffects: () => void) => void;
|
|
91
|
+
context: TContext | undefined;
|
|
92
|
+
debugRefreshInfos: BoundArray<RefreshDebugInfo<RefreshReasonWithGenericReasons<TDebugRefreshReason>, TDebugThunkInfo>>;
|
|
93
|
+
constructor(options: ReactiveGraphOptions);
|
|
94
|
+
makeRef<T>(val: T, options?: {
|
|
95
|
+
label?: string;
|
|
96
|
+
meta?: unknown;
|
|
97
|
+
equal?: (a: T, b: T) => boolean;
|
|
98
|
+
}): Ref<T>;
|
|
99
|
+
makeThunk<T>(getResult_: (get: GetAtom, addDebugInfo: (debugInfo: TDebugThunkInfo) => void, ctx: TContext, otelContext: otel.Context | undefined) => T, options?: {
|
|
100
|
+
label?: string;
|
|
101
|
+
meta?: any;
|
|
102
|
+
equal?: (a: T, b: T) => boolean;
|
|
103
|
+
/** Debug info for initializing the thunk (i.e. running it the first time) */
|
|
104
|
+
debugRefreshReason?: RefreshReasonWithGenericReasons<TDebugRefreshReason>;
|
|
105
|
+
} | undefined): Thunk<T, TContext>;
|
|
106
|
+
destroy(node: Atom<any, TContext> | Effect): void;
|
|
107
|
+
makeEffect(doEffect: (get: GetAtom, otelContext?: otel.Context) => void, options?: {
|
|
108
|
+
label?: string;
|
|
109
|
+
debugRefreshReason?: RefreshReasonWithGenericReasons<TDebugRefreshReason>;
|
|
110
|
+
} | undefined): Effect;
|
|
111
|
+
setRef<T>(ref: Ref<T>, val: T, options?: {
|
|
112
|
+
debugRefreshReason?: TDebugRefreshReason;
|
|
113
|
+
otelContext?: otel.Context;
|
|
114
|
+
} | undefined): void;
|
|
115
|
+
setRefs<T>(refs: [Ref<T>, T][], options?: {
|
|
116
|
+
debugRefreshReason?: TDebugRefreshReason;
|
|
117
|
+
otelContext?: otel.Context;
|
|
118
|
+
} | undefined): void;
|
|
119
|
+
/**
|
|
120
|
+
* Update the graph to be consistent with the current values of the root atoms.
|
|
121
|
+
* Generally we run this after a ref is updated.
|
|
122
|
+
* At the end of the refresh, we run any effects that were scheduled.
|
|
123
|
+
*
|
|
124
|
+
* @param roots Root atoms to start the refresh from
|
|
125
|
+
*/
|
|
126
|
+
label(atom: Atom<any, TContext> | Effect): string;
|
|
127
|
+
addEdge(superComp: Atom<any, TContext> | Effect, subComp: Atom<any, TContext>): void;
|
|
128
|
+
removeEdge(superComp: Atom<any, TContext> | Effect, subComp: Atom<any, TContext>): void;
|
|
129
|
+
updateAtomHeight(atom: Atom<any, TContext> | Effect): void;
|
|
130
|
+
private getSnapshot;
|
|
131
|
+
get atomsCount(): number;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=reactive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../src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