|
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'; |
8 | 2 | import { |
9 | 3 | AbstractQueryProcessor, |
10 | 4 | AbstractQueryProcessorOptions, |
@@ -89,18 +83,6 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW |
89 | 83 | query: WatchCompatibleQuery<RowType[]>; |
90 | 84 | } |
91 | 85 |
|
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 | | - |
104 | 86 | export interface DifferentialWatchedQueryListener<RowType> |
105 | 87 | extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> { |
106 | 88 | onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>; |
@@ -158,26 +140,13 @@ export class DifferentialQueryProcessor<RowType> |
158 | 140 | extends AbstractQueryProcessor<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>> |
159 | 141 | implements DifferentialWatchedQuery<RowType> |
160 | 142 | { |
161 | | - readonly state: DifferentialWatchedQueryState<RowType>; |
162 | | - |
163 | 143 | protected differentiator: WatchedQueryDifferentiator<RowType>; |
164 | 144 |
|
165 | 145 | constructor(protected options: DifferentialQueryProcessorOptions<RowType>) { |
166 | 146 | super(options); |
167 | | - this.state = this.constructInitialState(); |
168 | 147 | this.differentiator = options.differentiator ?? DEFAULT_WATCHED_QUERY_DIFFERENTIATOR; |
169 | 148 | } |
170 | 149 |
|
171 | | - protected constructInitialState(): DifferentialWatchedQueryState<RowType> { |
172 | | - return { |
173 | | - ...super.constructInitialState(), |
174 | | - diff: { |
175 | | - ...EMPTY_DIFFERENTIAL, |
176 | | - all: this.options.placeholderData |
177 | | - } |
178 | | - }; |
179 | | - } |
180 | | - |
181 | 150 | /* |
182 | 151 | * @returns If the sets are equal |
183 | 152 | */ |
@@ -274,7 +243,7 @@ export class DifferentialQueryProcessor<RowType> |
274 | 243 | await this.updateState({ isFetching: true }); |
275 | 244 | } |
276 | 245 |
|
277 | | - const partialStateUpdate: Partial<MutableDifferentialWatchedQueryState<RowType>> = {}; |
| 246 | + const partialStateUpdate: Partial<MutableWatchedQueryState<RowType[]>> = {}; |
278 | 247 |
|
279 | 248 | // Always run the query if an underlying table has changed |
280 | 249 | const result = await watchOptions.query.execute({ |
|
0 commit comments