Skip to content

Commit d4cf238

Browse files
cleanup readme and docs
1 parent 657eda7 commit d4cf238

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

packages/common/src/client/Query.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { WatchedQueryOptions } from './watched/WatchedQuery.js';
1212
export type QueryParam = string | number | boolean | null | undefined | bigint | Uint8Array;
1313

1414
/**
15-
* Options for building a query with {@link AbstractPowerSyncDatabase.query}.
16-
* This query will be executed with {@link AbstractPowerSyncDatabase.getAll}.
15+
* Options for building a query with {@link AbstractPowerSyncDatabase#query}.
16+
* This query will be executed with {@link AbstractPowerSyncDatabase#getAll}.
1717
*/
1818
export interface ArrayQueryDefinition<RowType = unknown> {
1919
sql: string;
@@ -37,7 +37,7 @@ export interface ArrayQueryDefinition<RowType = unknown> {
3737
export interface StandardWatchedQueryOptions<RowType> extends WatchedQueryOptions {
3838
/**
3939
* Optional comparator which processes the items of an array of rows.
40-
* The comparator compares the result set rows by index using the {@link ArrayComparatorOptions.compareBy} function.
40+
* The comparator compares the result set rows by index using the {@link ArrayComparatorOptions#compareBy} function.
4141
* The comparator reports a changed result set as soon as a row does not match the previous result set.
4242
*
4343
* @example
@@ -64,7 +64,7 @@ export interface Query<RowType> {
6464
* These changes might not be relevant to the query, but the query will emit a new result set.
6565
*
6666
* A {@link StandardWatchedQueryOptions#comparator} can be provided to limit the data emissions. The watched query will still
67-
* query the underlying DB on a underlying table changes, but the result will only be emitted if the comparator detects a change in the results.
67+
* query the underlying DB on underlying table changes, but the result will only be emitted if the comparator detects a change in the results.
6868
*
6969
* The comparator in this method is optimized and returns early as soon as it detects a change. Each data emission will correlate to a change in the result set,
7070
* but note that the result set will not maintain internal object references to the previous result set. If internal object references are needed,

packages/react/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function MyWidget() {
357357
return (
358358
// Other components
359359
// The data array is the same reference if no changes have occurred between fetches
360-
// Note: The array is a new reference is there are any changes in the result set (individual row object references are not preserved)
360+
// Note: The array is a new reference is there are any changes in the result set (individual row object references are preserved for unchanged rows)
361361
// Note: CatCollection requires memoization in order to prevent re-rendering (due to the parent re-rendering on fetch)
362362
<CatCollection cats={data}>
363363
)

packages/react/src/hooks/suspense/useWatchedQuerySuspenseSubscription.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import { createSuspendingPromise, useTemporaryHold } from './suspense-utils';
2323
* );
2424
* }
2525
*/
26-
export const useWatchedQuerySuspenseSubscription = <ResultType>(query: WatchedQuery<ResultType>) => {
26+
export const useWatchedQuerySuspenseSubscription = <
27+
ResultType = unknown,
28+
Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>
29+
>(
30+
query: Query
31+
): Query['state'] => {
2732
const { releaseHold } = useTemporaryHold(query);
2833

2934
// Force update state function
@@ -53,12 +58,7 @@ export const useWatchedQuerySuspenseSubscription = <ResultType>(query: WatchedQu
5358
throw query.state.error;
5459
} else if (!query.state.isLoading) {
5560
// Happy path data return
56-
return {
57-
data: query.state.data,
58-
refresh: async () => {
59-
// no-op for watched queries
60-
}
61-
};
61+
return query.state;
6262
} else {
6363
// Notify suspense is required
6464
throw createSuspendingPromise(query);

packages/react/src/hooks/suspense/useWatchedSuspenseQuery.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,5 @@ export const useWatchedSuspenseQuery = <T = any>(
3030
const store = getQueryStore(powerSync);
3131
const watchedQuery = store.getQuery(key, parsedQuery, options);
3232

33-
const result = useWatchedQuerySuspenseSubscription(watchedQuery);
34-
return {
35-
...result,
36-
// The result above is readonly, but this API expects a mutable array
37-
// We need to keep the same reference also.
38-
data: result.data as T[]
39-
};
33+
return useWatchedQuerySuspenseSubscription(watchedQuery);
4034
};

packages/react/src/hooks/watched/useWatchedQuerySubscription.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WatchedQuery, WatchedQueryState } from '@powersync/common';
1+
import { WatchedQuery } from '@powersync/common';
22
import React from 'react';
33

44
/**
@@ -15,9 +15,12 @@ import React from 'react';
1515
* }
1616
*
1717
*/
18-
export const useWatchedQuerySubscription = <ResultType = unknown>(
19-
query: WatchedQuery<ResultType>
20-
): WatchedQueryState<ResultType> => {
18+
export const useWatchedQuerySubscription = <
19+
ResultType = unknown,
20+
Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>
21+
>(
22+
query: Query
23+
): Query['state'] => {
2124
const [output, setOutputState] = React.useState(query.state);
2225

2326
React.useEffect(() => {

0 commit comments

Comments
 (0)