@powersync/react 0.0.0-dev-20250714151300 → 0.0.0-dev-20250722092404
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 +4 -4
- package/lib/QueryStore.js +2 -2
- package/lib/hooks/suspense/useSuspenseQuery.d.ts +3 -3
- package/lib/hooks/watched/useQuery.d.ts +4 -4
- package/lib/hooks/watched/useQuery.js +1 -1
- package/lib/hooks/watched/useWatchedQuery.js +2 -2
- package/lib/hooks/watched/watch-types.d.ts +9 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -346,8 +346,8 @@ function MyWidget() {
|
|
|
346
346
|
// Note that isFetching is set (by default) whenever the query is being fetched/checked.
|
|
347
347
|
// This will result in `MyWidget` re-rendering for any change to the `cats` table.
|
|
348
348
|
const { data, isLoading, isFetching } = useQuery(`SELECT * FROM cats WHERE breed = 'tabby'`, [], {
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
comparator: {
|
|
350
|
+
keyBy: (item) => item.id,
|
|
351
351
|
compareBy: (item) => JSON.stringify(item)
|
|
352
352
|
}
|
|
353
353
|
})
|
|
@@ -374,8 +374,8 @@ function MyWidget() {
|
|
|
374
374
|
// When reportFetching == false the object returned from useQuery will only be changed when the data, isLoading or error state changes.
|
|
375
375
|
// This method performs a comparison in memory in order to determine changes.
|
|
376
376
|
const { data, isLoading } = useQuery(`SELECT * FROM cats WHERE breed = 'tabby'`, [], {
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
comparator: {
|
|
378
|
+
keyBy: (item) => item.id,
|
|
379
379
|
compareBy: (item) => JSON.stringify(item)
|
|
380
380
|
}
|
|
381
381
|
reportFetching: false
|
package/lib/QueryStore.js
CHANGED
|
@@ -12,9 +12,9 @@ export class QueryStore {
|
|
|
12
12
|
if (this.cache.has(key)) {
|
|
13
13
|
return this.cache.get(key);
|
|
14
14
|
}
|
|
15
|
-
const watch = options.
|
|
15
|
+
const watch = options.comparator
|
|
16
16
|
? this.db.customQuery(query).differentialWatch({
|
|
17
|
-
|
|
17
|
+
comparator: options.comparator,
|
|
18
18
|
reportFetching: options.reportFetching,
|
|
19
19
|
throttleMs: options.throttleMs
|
|
20
20
|
})
|
|
@@ -27,10 +27,10 @@ import { ReadonlySuspenseQueryResult, SuspenseQueryResult } from './SuspenseQuer
|
|
|
27
27
|
* export const DiffContentComponent = () => {
|
|
28
28
|
* // A differential query will emit results when a change to the result set occurs.
|
|
29
29
|
* // The internal array object references are maintained for unchanged rows.
|
|
30
|
-
* // The returned lists array is read only when a `
|
|
30
|
+
* // The returned lists array is read only when a `comparator` is provided.
|
|
31
31
|
* const { data: lists } = useSuspenseQuery('SELECT * from lists', [], {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* comparator: {
|
|
33
|
+
* keyBy: (item) => item.id,
|
|
34
34
|
* compareBy: (item) => JSON.stringify(item)
|
|
35
35
|
* }
|
|
36
36
|
* });
|
|
@@ -19,10 +19,10 @@ import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryR
|
|
|
19
19
|
* export const DiffComponent = () => {
|
|
20
20
|
* // A differential query will emit results when a change to the result set occurs.
|
|
21
21
|
* // The internal array object references are maintained for unchanged rows.
|
|
22
|
-
* // The returned lists array is read only when a `
|
|
22
|
+
* // The returned lists array is read only when a `comparator` is provided.
|
|
23
23
|
* const { data: lists } = useQuery('SELECT * from lists', [], {
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* comparator: {
|
|
25
|
+
* keyBy: (item) => item.id,
|
|
26
26
|
* compareBy: (item) => JSON.stringify(item)
|
|
27
27
|
* }
|
|
28
28
|
* });
|
|
@@ -35,4 +35,4 @@ import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryR
|
|
|
35
35
|
* }
|
|
36
36
|
*/
|
|
37
37
|
export declare function useQuery<RowType = any>(query: string | CompilableQuery<RowType>, parameters?: any[], options?: AdditionalOptions): QueryResult<RowType>;
|
|
38
|
-
export declare function useQuery<RowType = any>(query: string | CompilableQuery<RowType>,
|
|
38
|
+
export declare function useQuery<RowType = any>(query: string | CompilableQuery<RowType>, parameters?: any[], options?: DifferentialHookOptions<RowType>): ReadonlyQueryResult<RowType>;
|
|
@@ -25,7 +25,7 @@ export function useQuery(query, parameters = [], options = {}) {
|
|
|
25
25
|
// Maintains backwards compatibility with previous versions
|
|
26
26
|
// Differentiation is opt-in by default
|
|
27
27
|
// We emit new data for each table change by default.
|
|
28
|
-
|
|
28
|
+
comparator: options.comparator
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -11,9 +11,9 @@ import { useWatchedQuerySubscription } from './useWatchedQuerySubscription';
|
|
|
11
11
|
export const useWatchedQuery = (options) => {
|
|
12
12
|
const { query, powerSync, queryChanged, options: hookOptions } = options;
|
|
13
13
|
const createWatchedQuery = React.useCallback(() => {
|
|
14
|
-
const watch = hookOptions.
|
|
14
|
+
const watch = hookOptions.comparator
|
|
15
15
|
? powerSync.customQuery(query).differentialWatch({
|
|
16
|
-
|
|
16
|
+
comparator: hookOptions.comparator,
|
|
17
17
|
reportFetching: hookOptions.reportFetching,
|
|
18
18
|
throttleMs: hookOptions.throttleMs
|
|
19
19
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DifferentialWatchedQueryComparator, SQLOnChangeOptions } from '@powersync/common';
|
|
2
2
|
export interface HookWatchOptions extends Omit<SQLOnChangeOptions, 'signal'> {
|
|
3
3
|
reportFetching?: boolean;
|
|
4
4
|
}
|
|
@@ -7,24 +7,26 @@ export interface AdditionalOptions extends HookWatchOptions {
|
|
|
7
7
|
}
|
|
8
8
|
export interface DifferentialHookOptions<RowType> extends HookWatchOptions {
|
|
9
9
|
/**
|
|
10
|
-
* Used to
|
|
10
|
+
* Used to compare result sets.
|
|
11
11
|
*
|
|
12
12
|
* By default the hook will requery on any dependent table change. This will
|
|
13
13
|
* emit a new hook result even if the result set has not changed.
|
|
14
14
|
*
|
|
15
|
-
* Specifying a {@link
|
|
16
|
-
* unchanged result sets
|
|
15
|
+
* Specifying a {@link DifferentialWatchedQueryComparator} will remove emissions for
|
|
16
|
+
* unchanged result sets.
|
|
17
|
+
* Furthermore, emitted `data` arrays will preserve object references between result set emissions
|
|
18
|
+
* for unchanged rows.
|
|
17
19
|
* @example
|
|
18
20
|
* ```javascript
|
|
19
21
|
* {
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* comparator: {
|
|
23
|
+
* keyBy: (item) => item.id,
|
|
22
24
|
* compareBy: (item) => JSON.stringify(item)
|
|
23
25
|
* }
|
|
24
26
|
* }
|
|
25
27
|
* ```
|
|
26
28
|
*/
|
|
27
|
-
|
|
29
|
+
comparator?: DifferentialWatchedQueryComparator<RowType>;
|
|
28
30
|
}
|
|
29
31
|
export type ReadonlyQueryResult<RowType> = {
|
|
30
32
|
readonly data: ReadonlyArray<Readonly<RowType>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20250722092404",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://docs.powersync.com",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@powersync/common": "0.0.0-dev-
|
|
25
|
+
"@powersync/common": "0.0.0-dev-20250722092404",
|
|
26
26
|
"react": "*"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"react": "18.3.1",
|
|
34
34
|
"react-dom": "18.3.1",
|
|
35
35
|
"react-error-boundary": "^4.1.0",
|
|
36
|
-
"@powersync/common": "0.0.0-dev-
|
|
37
|
-
"@powersync/web": "0.0.0-dev-
|
|
36
|
+
"@powersync/common": "0.0.0-dev-20250722092404",
|
|
37
|
+
"@powersync/web": "0.0.0-dev-20250722092404"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc -b",
|