Skip to content

Commit 1971f74

Browse files
committed
refactor: expose trackProp function
1 parent 03239f9 commit 1971f74

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

packages/query-core/src/queriesObserver.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,17 @@ export class QueriesObserver<
168168
return this.#combineResult(r ?? result, combine)
169169
},
170170
() => {
171-
const trackedMatches = matches.map((match, index) => {
171+
return matches.map((match, index) => {
172172
const observerResult = result[index]!
173173
return !match.defaultedQueryOptions.notifyOnChangeProps
174-
? match.observer.trackResult(observerResult, (accessedKey) => {
175-
// invoke getter on all observers to ensure proper (synchronized) tracking (#7000)
176-
matches.forEach((_, i) => {
177-
void trackedMatches[i]![accessedKey]
174+
? match.observer.trackResult(observerResult, (accessedProp) => {
175+
// track property on all observers to ensure proper (synchronized) tracking (#7000)
176+
matches.forEach((m) => {
177+
m.observer.trackProp(accessedProp)
178178
})
179179
})
180180
: observerResult
181181
})
182-
183-
return trackedMatches
184182
},
185183
]
186184
}

packages/query-core/src/queryObserver.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class QueryObserver<
247247

248248
trackResult(
249249
result: QueryObserverResult<TData, TError>,
250-
onPropertyTracked?: (key: keyof QueryObserverResult) => void,
250+
onPropTracked?: (key: keyof QueryObserverResult) => void,
251251
): QueryObserverResult<TData, TError> {
252252
const trackedResult = {} as QueryObserverResult<TData, TError>
253253

@@ -256,10 +256,8 @@ export class QueryObserver<
256256
configurable: false,
257257
enumerable: true,
258258
get: () => {
259-
if (!this.#trackedProps.has(key as keyof QueryObserverResult)) {
260-
this.#trackedProps.add(key as keyof QueryObserverResult)
261-
onPropertyTracked?.(key as keyof QueryObserverResult)
262-
}
259+
this.trackProp(key as keyof QueryObserverResult)
260+
onPropTracked?.(key as keyof QueryObserverResult)
263261
return result[key as keyof QueryObserverResult]
264262
},
265263
})
@@ -268,6 +266,10 @@ export class QueryObserver<
268266
return trackedResult
269267
}
270268

269+
trackProp(key: keyof QueryObserverResult) {
270+
this.#trackedProps.add(key)
271+
}
272+
271273
getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {
272274
return this.#currentQuery
273275
}

0 commit comments

Comments
 (0)