New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(QueryObserver): track queries as default #2987
Changes from 4 commits
66bf3ec
3b2af74
49069f7
5634c80
74d72ed
497d4ac
a34b472
17b2197
c5eb322
c57e400
fcd615c
0f4bf90
10215b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,27 +596,25 @@ export class QueryObserver< | |
return true | ||
} | ||
|
||
const { notifyOnChangeProps, notifyOnChangePropsExclusions } = this.options | ||
const { notifyOnChangeProps } = this.options | ||
|
||
if (!notifyOnChangeProps && !notifyOnChangePropsExclusions) { | ||
if (notifyOnChangeProps === 'all') { | ||
return true | ||
} | ||
|
||
if (notifyOnChangeProps === 'tracked' && !this.trackedProps.length) { | ||
if (!notifyOnChangeProps && !this.trackedProps.length) { | ||
return true | ||
} | ||
|
||
const includedProps = | ||
notifyOnChangeProps === 'tracked' | ||
? this.trackedProps | ||
: notifyOnChangeProps | ||
const includedProps = !notifyOnChangeProps | ||
? this.trackedProps | ||
: notifyOnChangeProps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. negated ifs are pretty hard to read imo, so is this the same as:
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree on using |
||
|
||
return Object.keys(result).some(key => { | ||
const typedKey = key as keyof QueryObserverResult | ||
const changed = result[typedKey] !== prevResult[typedKey] | ||
const isIncluded = includedProps?.some(x => x === key) | ||
const isExcluded = notifyOnChangePropsExclusions?.some(x => x === key) | ||
return changed && !isExcluded && (!includedProps || isIncluded) | ||
return changed && (!includedProps || isIncluded) | ||
}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,11 +160,7 @@ export interface QueryObserverOptions< | |
* When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change. | ||
* When set to `tracked`, access to properties will be tracked, and the component will only re-render when one of the tracked properties change. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment is no longer accurate here :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah - this is for sure part of the docs i need to update |
||
*/ | ||
notifyOnChangeProps?: Array<keyof InfiniteQueryObserverResult> | 'tracked' | ||
/** | ||
* If set, the component will not re-render if any of the listed properties change. | ||
*/ | ||
notifyOnChangePropsExclusions?: Array<keyof InfiniteQueryObserverResult> | ||
notifyOnChangeProps?: Array<keyof InfiniteQueryObserverResult> | 'all' | ||
/** | ||
* This callback will fire any time the query successfully fetches new data or the cache is updated via `setQueryData`. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let’s combine these two if statements that return true with an ||