@livestore/react 0.2.0-dev.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/useScopedQuery.d.ts
CHANGED
|
@@ -7,6 +7,17 @@ export type DepKey = string | number | ReadonlyArray<string | number>;
|
|
|
7
7
|
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
8
8
|
*
|
|
9
9
|
* The `key` is used to determine whether the a new query should be created or if the existing one should be reused.
|
|
10
|
+
* This hook should be used instead of `useQuery` when the query should be dynamically created based on some props.
|
|
11
|
+
* Otherwise when using `useQuery` the query will be leaked (i.e. never destroyed) when the component re-renders/unmounts.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const issue = useScopedQuery(() => queryDb(tables.issues.query.where('id', issueId).first()), ['issue-details', issueId])
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Important: On Expo/React Native please make sure the key contains a globally unique identifier, otherwise the query might get reused unintentionally.
|
|
19
|
+
* Example: `['issue-details', issueId]`
|
|
20
|
+
* See this issue to track progress: https://github.com/livestorejs/livestore/issues/231
|
|
10
21
|
*/
|
|
11
22
|
export declare const useScopedQuery: <TResult>(makeQuery: () => LiveQuery<TResult>, key: DepKey) => TResult;
|
|
12
23
|
export declare const useScopedQueryRef: <TResult>(makeQuery: () => LiveQuery<TResult>, key: DepKey) => React.MutableRefObject<TResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScopedQuery.d.ts","sourceRoot":"","sources":["../src/useScopedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAuBzB,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;AAErE
|
|
1
|
+
{"version":3,"file":"useScopedQuery.d.ts","sourceRoot":"","sources":["../src/useScopedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAuBzB,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;AAErE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,MAAM,KAAG,OAChD,CAAA;AAE3C,eAAO,MAAM,iBAAiB,GAAI,OAAO,aAC5B,MAAM,SAAS,CAAC,OAAO,CAAC,OAC9B,MAAM,KACV,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAIhC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,OAAO,EAAE,UAAU,SAAS,SAAS,aAC3D,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,OACnE,MAAM,YACD;IACR,IAAI,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,CAAA;KAC7B,CAAA;CACF,KACA;IAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAA;CA4ErE,CAAA"}
|
package/dist/useScopedQuery.js
CHANGED
|
@@ -11,6 +11,17 @@ const cache = new Map();
|
|
|
11
11
|
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
12
12
|
*
|
|
13
13
|
* The `key` is used to determine whether the a new query should be created or if the existing one should be reused.
|
|
14
|
+
* This hook should be used instead of `useQuery` when the query should be dynamically created based on some props.
|
|
15
|
+
* Otherwise when using `useQuery` the query will be leaked (i.e. never destroyed) when the component re-renders/unmounts.
|
|
16
|
+
*
|
|
17
|
+
* Example:
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const issue = useScopedQuery(() => queryDb(tables.issues.query.where('id', issueId).first()), ['issue-details', issueId])
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Important: On Expo/React Native please make sure the key contains a globally unique identifier, otherwise the query might get reused unintentionally.
|
|
23
|
+
* Example: `['issue-details', issueId]`
|
|
24
|
+
* See this issue to track progress: https://github.com/livestorejs/livestore/issues/231
|
|
14
25
|
*/
|
|
15
26
|
export const useScopedQuery = (makeQuery, key) => useScopedQueryRef(makeQuery, key).current;
|
|
16
27
|
export const useScopedQueryRef = (makeQuery, key) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScopedQuery.js","sourceRoot":"","sources":["../src/useScopedQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,0GAA0G;AAC1G,2FAA2F;AAC3F,2GAA2G;AAC3G,0FAA0F;AAC1F,MAAM,KAAK,GAAG,IAAI,GAAG,EAYlB,CAAA;AAIH
|
|
1
|
+
{"version":3,"file":"useScopedQuery.js","sourceRoot":"","sources":["../src/useScopedQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MA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6
|
".": {
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@opentelemetry/api": "^1.9.0",
|
|
25
|
-
"@livestore/
|
|
26
|
-
"@livestore/
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/
|
|
25
|
+
"@livestore/utils": "0.2.0",
|
|
26
|
+
"@livestore/db-schema": "0.2.0",
|
|
27
|
+
"@livestore/livestore": "0.2.0",
|
|
28
|
+
"@livestore/common": "0.2.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@opentelemetry/sdk-trace-base": "1.27.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"typescript": "5.5.4",
|
|
40
40
|
"vite": "5.4.10",
|
|
41
41
|
"vitest": "^2.1.4",
|
|
42
|
-
"@livestore/web": "0.2.0
|
|
42
|
+
"@livestore/web": "0.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^18"
|
package/src/useScopedQuery.ts
CHANGED
|
@@ -30,6 +30,17 @@ export type DepKey = string | number | ReadonlyArray<string | number>
|
|
|
30
30
|
* Creates a query, subscribes and destroys it when the component unmounts.
|
|
31
31
|
*
|
|
32
32
|
* The `key` is used to determine whether the a new query should be created or if the existing one should be reused.
|
|
33
|
+
* This hook should be used instead of `useQuery` when the query should be dynamically created based on some props.
|
|
34
|
+
* Otherwise when using `useQuery` the query will be leaked (i.e. never destroyed) when the component re-renders/unmounts.
|
|
35
|
+
*
|
|
36
|
+
* Example:
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const issue = useScopedQuery(() => queryDb(tables.issues.query.where('id', issueId).first()), ['issue-details', issueId])
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Important: On Expo/React Native please make sure the key contains a globally unique identifier, otherwise the query might get reused unintentionally.
|
|
42
|
+
* Example: `['issue-details', issueId]`
|
|
43
|
+
* See this issue to track progress: https://github.com/livestorejs/livestore/issues/231
|
|
33
44
|
*/
|
|
34
45
|
export const useScopedQuery = <TResult>(makeQuery: () => LiveQuery<TResult>, key: DepKey): TResult =>
|
|
35
46
|
useScopedQueryRef(makeQuery, key).current
|