Skip to content

Commit 3a6520e

Browse files
use enums
1 parent 4f54dab commit 3a6520e

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ export interface PowerSyncDatabaseOptionsWithSettings extends BasePowerSyncDatab
7272
database: SQLOpenOptions;
7373
}
7474

75+
export enum IncrementalWatchMode {
76+
COMPARISON = 'comparison'
77+
}
78+
7579
export interface WatchComparatorOptions<DataType> {
76-
mode: 'comparison';
80+
mode: IncrementalWatchMode.COMPARISON;
7781
comparator?: WatchedQueryComparator<DataType>;
7882
}
7983

@@ -891,7 +895,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
891895
const { watch, processor } = options;
892896

893897
switch (options.processor?.mode) {
894-
case 'comparison':
898+
case IncrementalWatchMode.COMPARISON:
895899
default:
896900
return new OnChangeQueryProcessor({
897901
db: this,
@@ -936,7 +940,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
936940
throttleMs: options?.throttleMs ?? DEFAULT_WATCH_THROTTLE_MS
937941
},
938942
processor: options?.processor ?? {
939-
mode: 'comparison',
943+
mode: IncrementalWatchMode.COMPARISON,
940944
comparator: FalsyComparator
941945
}
942946
});

packages/react/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function MyWidget() {
346346
// This will result in `MyWidget` re-rendering for any change to the `cats` table.
347347
const { data, isLoading, isFetching } = useQuery(`SELECT * FROM cats WHERE breed = 'tabby'`, [], {
348348
processor: {
349-
mode: 'comparison',
349+
mode: IncrementalWatchMode.COMPARISON,
350350
comparator: new ArrayComparator({
351351
compareBy: (cat) => JSON.stringify(cat)
352352
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CompilableQuery, FalsyComparator } from '@powersync/common';
1+
import { CompilableQuery, FalsyComparator, IncrementalWatchMode } from '@powersync/common';
22
import { AdditionalOptions } from '../watched/watch-types';
33
import { SuspenseQueryResult } from './SuspenseQueryResult';
44
import { useSingleSuspenseQuery } from './useSingleSuspenseQuery';
@@ -37,7 +37,7 @@ export const useSuspenseQuery = <T = any>(
3737
return useWatchedSuspenseQuery<T>(query, parameters, {
3838
...options,
3939
processor: options.processor ?? {
40-
mode: 'comparison',
40+
mode: IncrementalWatchMode.COMPARISON,
4141
comparator: FalsyComparator // Default comparator that always reports changed result sets
4242
}
4343
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FalsyComparator, type CompilableQuery } from '@powersync/common';
1+
import { FalsyComparator, IncrementalWatchMode, type CompilableQuery } from '@powersync/common';
22
import { usePowerSync } from '../PowerSyncContext';
33
import { useSingleQuery } from './useSingleQuery';
44
import { useWatchedQuery } from './useWatchedQuery';
@@ -48,7 +48,7 @@ export const useQuery = <RowType = any>(
4848
// Maintains backwards compatibility with previous versions
4949
// Comparisons are opt-in by default
5050
// We emit new data for each table change by default.
51-
mode: 'comparison',
51+
mode: IncrementalWatchMode.COMPARISON,
5252
comparator: FalsyComparator
5353
}
5454
}

packages/vue/src/composables/useWatchedQuery.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { type CompilableQuery, FalsyComparator, ParsedQuery, parseQuery } from '@powersync/common';
1+
import {
2+
type CompilableQuery,
3+
FalsyComparator,
4+
IncrementalWatchMode,
5+
ParsedQuery,
6+
parseQuery
7+
} from '@powersync/common';
28
import { type MaybeRef, type Ref, ref, toValue, watchEffect } from 'vue';
39
import { usePowerSync } from './powerSync';
410
import { AdditionalOptions, WatchedQueryResult } from './useSingleQuery';
@@ -63,7 +69,7 @@ export const useWatchedQuery = <T = any>(
6369
}
6470
},
6571
processor: options.processor ?? {
66-
mode: 'comparison',
72+
mode: IncrementalWatchMode.COMPARISON, // Maintains backwards compatibility with previous versions
6773
// Defaults to no comparison if no processor is provided
6874
comparator: FalsyComparator
6975
}

0 commit comments

Comments
 (0)