Skip to content

Commit 7920d37

Browse files
Remove diff from watched query state for real this time.
1 parent 155eaea commit 7920d37

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

packages/common/src/client/watched/processors/DifferentialQueryProcessor.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
WatchCompatibleQuery,
3-
WatchedQuery,
4-
WatchedQueryListener,
5-
WatchedQueryOptions,
6-
WatchedQueryState
7-
} from '../WatchedQuery.js';
1+
import { WatchCompatibleQuery, WatchedQuery, WatchedQueryListener, WatchedQueryOptions } from '../WatchedQuery.js';
82
import {
93
AbstractQueryProcessor,
104
AbstractQueryProcessorOptions,
@@ -89,18 +83,6 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
8983
query: WatchCompatibleQuery<RowType[]>;
9084
}
9185

92-
export interface DifferentialWatchedQueryState<RowType> extends WatchedQueryState<ReadonlyArray<Readonly<RowType>>> {
93-
/**
94-
* The difference between the current and previous result set.
95-
*/
96-
readonly diff: WatchedQueryDifferential<RowType>;
97-
}
98-
99-
type MutableDifferentialWatchedQueryState<RowType> = MutableWatchedQueryState<RowType[]> & {
100-
data: RowType[];
101-
diff: WatchedQueryDifferential<RowType>;
102-
};
103-
10486
export interface DifferentialWatchedQueryListener<RowType>
10587
extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
10688
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
@@ -158,26 +140,13 @@ export class DifferentialQueryProcessor<RowType>
158140
extends AbstractQueryProcessor<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>>
159141
implements DifferentialWatchedQuery<RowType>
160142
{
161-
readonly state: DifferentialWatchedQueryState<RowType>;
162-
163143
protected differentiator: WatchedQueryDifferentiator<RowType>;
164144

165145
constructor(protected options: DifferentialQueryProcessorOptions<RowType>) {
166146
super(options);
167-
this.state = this.constructInitialState();
168147
this.differentiator = options.differentiator ?? DEFAULT_WATCHED_QUERY_DIFFERENTIATOR;
169148
}
170149

171-
protected constructInitialState(): DifferentialWatchedQueryState<RowType> {
172-
return {
173-
...super.constructInitialState(),
174-
diff: {
175-
...EMPTY_DIFFERENTIAL,
176-
all: this.options.placeholderData
177-
}
178-
};
179-
}
180-
181150
/*
182151
* @returns If the sets are equal
183152
*/
@@ -274,7 +243,7 @@ export class DifferentialQueryProcessor<RowType>
274243
await this.updateState({ isFetching: true });
275244
}
276245

277-
const partialStateUpdate: Partial<MutableDifferentialWatchedQueryState<RowType>> = {};
246+
const partialStateUpdate: Partial<MutableWatchedQueryState<RowType[]>> = {};
278247

279248
// Always run the query if an underlying table has changed
280249
const result = await watchOptions.query.execute({
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// import { WatchedQuery } from '@powersync/common';
2+
// import { reactive, Ref, ref, UnwrapRef, watchEffect } from 'vue';
3+
4+
// /**
5+
// * A composable to access and subscribe to the results of an existing {@link WatchedQuery} instance.
6+
// * @example
7+
// * ```vue
8+
// * <script setup>
9+
// * import { useQuery } from '@powersync/vue';
10+
// *
11+
// * const { data, isLoading, isFetching, error} = useQuery(listsQuery);
12+
// * </script>
13+
// *
14+
// * <template>
15+
// * <div v-if="isLoading">Loading...</div>
16+
// * <div v-else-if="isFetching">Updating results...</div>
17+
// *
18+
// * <div v-if="error">{{ error }}</div>
19+
// * <ul v-else>
20+
// * <li v-for="l in data" :key="l.id">{{ l.name }}</li>
21+
// * </ul>
22+
// * </template>
23+
// * ```
24+
// */
25+
// export const useWatchedQuerySubscription = <
26+
// ResultType = unknown,
27+
// Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>
28+
// >(
29+
// query: Query
30+
// ) => {
31+
// const state = reactive(query.state);
32+
33+
// return state;
34+
// };

0 commit comments

Comments
 (0)