Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

queryObserver.ts

824 lines22.9 KB

1import { focusManager } from './focusManager'
2import { notifyManager } from './notifyManager'
3import { fetchState } from './query'
4import { Subscribable } from './subscribable'
5import { pendingThenable } from './thenable'
6import {
7 isServer,
8 isValidTimeout,
9 noop,
10 replaceData,
11 resolveEnabled,
12 resolveStaleTime,
13 shallowEqualObjects,
14 timeUntilStale,
15} from './utils'
16import type { FetchOptions, Query, QueryState } from './query'
17import type { QueryClient } from './queryClient'
18import type { PendingThenable, Thenable } from './thenable'
19import type {
20 DefaultError,
21 DefaultedQueryObserverOptions,
22 PlaceholderDataFunction,
23 QueryKey,
24 QueryObserverBaseResult,
25 QueryObserverOptions,
26 QueryObserverResult,
27 QueryOptions,
28 RefetchOptions,
29} from './types'
30​
31type QueryObserverListener<TData, TError> = (
32 result: QueryObserverResult<TData, TError>,
33) => void
34​
35interface ObserverFetchOptions extends FetchOptions {
36 throwOnError?: boolean
38​
39export class QueryObserver<
40 TQueryFnData = unknown,
41 TError = DefaultError,
42 TData = TQueryFnData,
43 TQueryData = TQueryFnData,
44 TQueryKey extends QueryKey = QueryKey,
45> extends Subscribable<QueryObserverListener<TData, TError>> {
46 #client: QueryClient
47 #currentQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> = undefined!
48 #currentQueryInitialState: QueryState<TQueryData, TError> = undefined!
49 #currentResult: QueryObserverResult<TData, TError> = undefined!
50 #currentResultState?: QueryState<TQueryData, TError>
51 #currentResultOptions?: QueryObserverOptions<
52 TQueryFnData,
53 TError,
54 TData,
55 TQueryData,
56 TQueryKey
57 >
58 #currentThenable: Thenable<TData>
59 #selectError: TError | null
60 #selectFn?: (data: TQueryData) => TData
61 #selectResult?: TData
62 // This property keeps track of the last query with defined data.
63 // It will be used to pass the previous data and query to the placeholder function between renders.
64 #lastQueryWithDefinedData?: Query<TQueryFnData, TError, TQueryData, TQueryKey>
65 #staleTimeoutId?: ReturnType<typeof setTimeout>
66 #refetchIntervalId?: ReturnType<typeof setInterval>
67 #currentRefetchInterval?: number | false
68 #trackedProps = new Set<keyof QueryObserverResult>()
69​
70 constructor(
71 client: QueryClient,
72 public options: QueryObserverOptions<
73 TQueryFnData,
74 TError,
75 TData,
76 TQueryData,
77 TQueryKey
78 >,
79 ) {
80 super()
81​
82 this.#client = client
83 this.#selectError = null
84 this.#currentThenable = pendingThenable()
85​
86 this.bindMethods()
87 this.setOptions(options)
88​
89 if (!this.options.experimental_prefetchInRender) {
90 this.#currentThenable.reject(
91 new Error('experimental_prefetchInRender feature flag is not enabled'),
92 )
93 }
94 }
95​
96 protected bindMethods(): void {
97 this.refetch = this.refetch.bind(this)
98 }
99​
100 protected onSubscribe(): void {
101 if (this.listeners.size === 1) {
102 this.#currentQuery.addObserver(this)
103​
104 if (shouldFetchOnMount(this.#currentQuery, this.options)) {
105 this.#executeFetch()
106 } else {
107 this.updateResult()
108 }
109​
110 this.#updateTimers()
111 }
112 }
113​
114 protected onUnsubscribe(): void {
115 if (!this.hasListeners()) {
116 this.destroy()
117 }
118 }
119​
120 shouldFetchOnReconnect(): boolean {
121 return shouldFetchOn(
122 this.#currentQuery,
123 this.options,
124 this.options.refetchOnReconnect,
125 )
126 }
127​
128 shouldFetchOnWindowFocus(): boolean {
129 return shouldFetchOn(
130 this.#currentQuery,
131 this.options,
132 this.options.refetchOnWindowFocus,
133 )
134 }
135​
136 destroy(): void {
137 this.listeners = new Set()
138 this.#clearStaleTimeout()
139 this.#clearRefetchInterval()
140 this.#currentQuery.removeObserver(this)
141 }
142​
143 setOptions(
144 options: QueryObserverOptions<
145 TQueryFnData,
146 TError,
147 TData,
148 TQueryData,
149 TQueryKey
150 >,
151 ): void {
152 const prevOptions = this.options
153 const prevQuery = this.#currentQuery
154​
155 this.options = this.#client.defaultQueryOptions(options)
156​
157 if (
158 this.options.enabled !== undefined &&
159 typeof this.options.enabled !== 'boolean' &&
160 typeof this.options.enabled !== 'function' &&
161 typeof resolveEnabled(this.options.enabled, this.#currentQuery) !==
162 'boolean'
163 ) {
164 throw new Error(
165 'Expected enabled to be a boolean or a callback that returns a boolean',
166 )
167 }
168​
169 this.#updateQuery()
170 this.#currentQuery.setOptions(this.options)
171​
172 if (
173 prevOptions._defaulted &&
174 !shallowEqualObjects(this.options, prevOptions)
175 ) {
176 this.#client.getQueryCache().notify({
177 type: 'observerOptionsUpdated',
178 query: this.#currentQuery,
179 observer: this,
180 })
181 }
182​
183 const mounted = this.hasListeners()
184​
185 // Fetch if there are subscribers
186 if (
187 mounted &&
188 shouldFetchOptionally(
189 this.#currentQuery,
190 prevQuery,
191 this.options,
192 prevOptions,
193 )
194 ) {
195 this.#executeFetch()
196 }
197​
198 // Update result
199 this.updateResult()
200​
201 // Update stale interval if needed
202 if (
203 mounted &&
204 (this.#currentQuery !== prevQuery ||
205 resolveEnabled(this.options.enabled, this.#currentQuery) !==
206 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
207 resolveStaleTime(this.options.staleTime, this.#currentQuery) !==
208 resolveStaleTime(prevOptions.staleTime, this.#currentQuery))
209 ) {
210 this.#updateStaleTimeout()
211 }
212​
213 const nextRefetchInterval = this.#computeRefetchInterval()
214​
215 // Update refetch interval if needed
216 if (
217 mounted &&
218 (this.#currentQuery !== prevQuery ||
219 resolveEnabled(this.options.enabled, this.#currentQuery) !==
220 resolveEnabled(prevOptions.enabled, this.#currentQuery) ||
221 nextRefetchInterval !== this.#currentRefetchInterval)
222 ) {
223 this.#updateRefetchInterval(nextRefetchInterval)
224 }
225 }
226​
227 getOptimisticResult(
228 options: DefaultedQueryObserverOptions<
229 TQueryFnData,
230 TError,
231 TData,
232 TQueryData,
233 TQueryKey
234 >,
235 ): QueryObserverResult<TData, TError> {
236 const query = this.#client.getQueryCache().build(this.#client, options)
237​
238 const result = this.createResult(query, options)
239​
240 if (shouldAssignObserverCurrentProperties(this, result)) {
241 // this assigns the optimistic result to the current Observer
242 // because if the query function changes, useQuery will be performing
243 // an effect where it would fetch again.
244 // When the fetch finishes, we perform a deep data cloning in order
245 // to reuse objects references. This deep data clone is performed against
246 // the `observer.currentResult.data` property
247 // When QueryKey changes, we refresh the query and get new `optimistic`
248 // result, while we leave the `observer.currentResult`, so when new data
249 // arrives, it finds the old `observer.currentResult` which is related
250 // to the old QueryKey. Which means that currentResult and selectData are
251 // out of sync already.
252 // To solve this, we move the cursor of the currentResult every time
253 // an observer reads an optimistic value.
254​
255 // When keeping the previous data, the result doesn't change until new
256 // data arrives.
257 this.#currentResult = result
258 this.#currentResultOptions = this.options
259 this.#currentResultState = this.#currentQuery.state
260 }
261 return result
262 }
263​
264 getCurrentResult(): QueryObserverResult<TData, TError> {
265 return this.#currentResult
266 }
267​
268 trackResult(
269 result: QueryObserverResult<TData, TError>,
270 onPropTracked?: (key: keyof QueryObserverResult) => void,
271 ): QueryObserverResult<TData, TError> {
272 return new Proxy(result, {
273 get: (target, key) => {
274 this.trackProp(key as keyof QueryObserverResult)
275 onPropTracked?.(key as keyof QueryObserverResult)
276 return Reflect.get(target, key)
277 },
278 })
279 }
280​
281 trackProp(key: keyof QueryObserverResult) {
282 this.#trackedProps.add(key)
283 }
284​
285 getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {
286 return this.#currentQuery
287 }
288​
289 refetch({ ...options }: RefetchOptions = {}): Promise<
290 QueryObserverResult<TData, TError>
291 > {
292 return this.fetch({
293 ...options,
294 })
295 }
296​
297 fetchOptimistic(
298 options: QueryObserverOptions<
299 TQueryFnData,
300 TError,
301 TData,
302 TQueryData,
303 TQueryKey
304 >,
305 ): Promise<QueryObserverResult<TData, TError>> {
306 const defaultedOptions = this.#client.defaultQueryOptions(options)
307​
308 const query = this.#client
309 .getQueryCache()
310 .build(this.#client, defaultedOptions)
311​
312 return query.fetch().then(() => this.createResult(query, defaultedOptions))
313 }
314​
315 protected fetch(
316 fetchOptions: ObserverFetchOptions,
317 ): Promise<QueryObserverResult<TData, TError>> {
318 return this.#executeFetch({
319 ...fetchOptions,
320 cancelRefetch: fetchOptions.cancelRefetch ?? true,
321 }).then(() => {
322 this.updateResult()
323 return this.#currentResult
324 })
325 }
326​
327 #executeFetch(
328 fetchOptions?: Omit<ObserverFetchOptions, 'initialPromise'>,
329 ): Promise<TQueryData | undefined> {
330 // Make sure we reference the latest query as the current one might have been removed
331 this.#updateQuery()
332​
333 // Fetch
334 let promise: Promise<TQueryData | undefined> = this.#currentQuery.fetch(
335 this.options as QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey>,
336 fetchOptions,
337 )
338​
339 if (!fetchOptions?.throwOnError) {
340 promise = promise.catch(noop)
341 }
342​
343 return promise
344 }
345​
346 #updateStaleTimeout(): void {
347 this.#clearStaleTimeout()
348 const staleTime = resolveStaleTime(
349 this.options.staleTime,
350 this.#currentQuery,
351 )
352​
353 if (isServer || this.#currentResult.isStale || !isValidTimeout(staleTime)) {
354 return
355 }
356​
357 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
358​
359 // The timeout is sometimes triggered 1 ms before the stale time expiration.
360 // To mitigate this issue we always add 1 ms to the timeout.
361 const timeout = time + 1
362​
363 this.#staleTimeoutId = setTimeout(() => {
364 if (!this.#currentResult.isStale) {
365 this.updateResult()
366 }
367 }, timeout)
368 }
369​
370 #computeRefetchInterval() {
371 return (
372 (typeof this.options.refetchInterval === 'function'
373 ? this.options.refetchInterval(this.#currentQuery)
374 : this.options.refetchInterval) ?? false
375 )
376 }
377​
378 #updateRefetchInterval(nextInterval: number | false): void {
379 this.#clearRefetchInterval()
380​
381 this.#currentRefetchInterval = nextInterval
382​
383 if (
384 isServer ||
385 resolveEnabled(this.options.enabled, this.#currentQuery) === false ||
386 !isValidTimeout(this.#currentRefetchInterval) ||
387 this.#currentRefetchInterval === 0
388 ) {
389 return
390 }
391​
392 this.#refetchIntervalId = setInterval(() => {
393 if (
394 this.options.refetchIntervalInBackground ||
395 focusManager.isFocused()
396 ) {
397 this.#executeFetch()
398 }
399 }, this.#currentRefetchInterval)
400 }
401​
402 #updateTimers(): void {
403 this.#updateStaleTimeout()
404 this.#updateRefetchInterval(this.#computeRefetchInterval())
405 }
406​
407 #clearStaleTimeout(): void {
408 if (this.#staleTimeoutId) {
409 clearTimeout(this.#staleTimeoutId)
410 this.#staleTimeoutId = undefined
411 }
412 }
413​
414 #clearRefetchInterval(): void {
415 if (this.#refetchIntervalId) {
416 clearInterval(this.#refetchIntervalId)
417 this.#refetchIntervalId = undefined
418 }
419 }
420​
421 protected createResult(
422 query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
423 options: QueryObserverOptions<
424 TQueryFnData,
425 TError,
426 TData,
427 TQueryData,
428 TQueryKey
429 >,
430 ): QueryObserverResult<TData, TError> {
431 const prevQuery = this.#currentQuery
432 const prevOptions = this.options
433 const prevResult = this.#currentResult as
434 | QueryObserverResult<TData, TError>
435 | undefined
436 const prevResultState = this.#currentResultState
437 const prevResultOptions = this.#currentResultOptions
438 const queryChange = query !== prevQuery
439 const queryInitialState = queryChange
440 ? query.state
441 : this.#currentQueryInitialState
442​
443 const { state } = query
444 let newState = { ...state }
445 let isPlaceholderData = false
446 let data: TData | undefined
447​
448 // Optimistically set result in fetching state if needed
449 if (options._optimisticResults) {
450 const mounted = this.hasListeners()
451​
452 const fetchOnMount = !mounted && shouldFetchOnMount(query, options)
453​
454 const fetchOptionally =
455 mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)
456​
457 if (fetchOnMount || fetchOptionally) {
458 newState = {
459 ...newState,
460 ...fetchState(state.data, query.options),
461 }
462 }
463 if (options._optimisticResults === 'isRestoring') {
464 newState.fetchStatus = 'idle'
465 }
466 }
467​
468 let { error, errorUpdatedAt, status } = newState
469​
470 // Per default, use query data
471 data = newState.data as unknown as TData
472 let skipSelect = false
473​
474 // use placeholderData if needed
475 if (
476 options.placeholderData !== undefined &&
477 data === undefined &&
478 status === 'pending'
479 ) {
480 let placeholderData
481​
482 // Memoize placeholder data
483 if (
484 prevResult?.isPlaceholderData &&
485 options.placeholderData === prevResultOptions?.placeholderData
486 ) {
487 placeholderData = prevResult.data
488 // we have to skip select when reading this memoization
489 // because prevResult.data is already "selected"
490 skipSelect = true
491 } else {
492 // compute placeholderData
493 placeholderData =
494 typeof options.placeholderData === 'function'
495 ? (
496 options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>
497 )(
498 this.#lastQueryWithDefinedData?.state.data,
499 this.#lastQueryWithDefinedData as any,
500 )
501 : options.placeholderData
502 }
503​
504 if (placeholderData !== undefined) {
505 status = 'success'
506 data = replaceData(
507 prevResult?.data,
508 placeholderData as unknown,
509 options,
510 ) as TData
511 isPlaceholderData = true
512 }
513 }
514​
515 // Select data if needed
516 // this also runs placeholderData through the select function
517 if (options.select && data !== undefined && !skipSelect) {
518 // Memoize select result
519 if (
520 prevResult &&
521 data === prevResultState?.data &&
522 options.select === this.#selectFn
523 ) {
524 data = this.#selectResult
525 } else {
526 try {
527 this.#selectFn = options.select
528 data = options.select(data as any)
529 data = replaceData(prevResult?.data, data, options)
530 this.#selectResult = data
531 this.#selectError = null
532 } catch (selectError) {
533 this.#selectError = selectError as TError
534 }
535 }
536 }
537​
538 if (this.#selectError) {
539 error = this.#selectError as any
540 data = this.#selectResult
541 errorUpdatedAt = Date.now()
542 status = 'error'
543 }
544​
545 const isFetching = newState.fetchStatus === 'fetching'
546 const isPending = status === 'pending'
547 const isError = status === 'error'
548​
549 const isLoading = isPending && isFetching
550 const hasData = data !== undefined
551​
552 const result: QueryObserverBaseResult<TData, TError> = {
553 status,
554 fetchStatus: newState.fetchStatus,
555 isPending,
556 isSuccess: status === 'success',
557 isError,
558 isInitialLoading: isLoading,
559 isLoading,
560 data,
561 dataUpdatedAt: newState.dataUpdatedAt,
562 error,
563 errorUpdatedAt,
564 failureCount: newState.fetchFailureCount,
565 failureReason: newState.fetchFailureReason,
566 errorUpdateCount: newState.errorUpdateCount,
567 isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
568 isFetchedAfterMount:
569 newState.dataUpdateCount > queryInitialState.dataUpdateCount ||
570 newState.errorUpdateCount > queryInitialState.errorUpdateCount,
571 isFetching,
572 isRefetching: isFetching && !isPending,
573 isLoadingError: isError && !hasData,
574 isPaused: newState.fetchStatus === 'paused',
575 isPlaceholderData,
576 isRefetchError: isError && hasData,
577 isStale: isStale(query, options),
578 refetch: this.refetch,
579 promise: this.#currentThenable,
580 isEnabled: resolveEnabled(options.enabled, query) !== false,
581 }
582​
583 const nextResult = result as QueryObserverResult<TData, TError>
584​
585 if (this.options.experimental_prefetchInRender) {
586 const finalizeThenableIfPossible = (thenable: PendingThenable<TData>) => {
587 if (nextResult.status === 'error') {
588 thenable.reject(nextResult.error)
589 } else if (nextResult.data !== undefined) {
590 thenable.resolve(nextResult.data)
591 }
592 }
593​
594 /**
595 * Create a new thenable and result promise when the results have changed
596 */
597 const recreateThenable = () => {
598 const pending =
599 (this.#currentThenable =
600 nextResult.promise =
601 pendingThenable())
602​
603 finalizeThenableIfPossible(pending)
604 }
605​
606 const prevThenable = this.#currentThenable
607 switch (prevThenable.status) {
608 case 'pending':
609 // Finalize the previous thenable if it was pending
610 // and we are still observing the same query
611 if (query.queryHash === prevQuery.queryHash) {
612 finalizeThenableIfPossible(prevThenable)
613 }
614 break
615 case 'fulfilled':
616 if (
617 nextResult.status === 'error' ||
618 nextResult.data !== prevThenable.value
619 ) {
620 recreateThenable()
621 }
622 break
623 case 'rejected':
624 if (
625 nextResult.status !== 'error' ||
626 nextResult.error !== prevThenable.reason
627 ) {
628 recreateThenable()
629 }
630 break
631 }
632 }
633​
634 return nextResult
635 }
636​
637 updateResult(): void {
638 const prevResult = this.#currentResult as
639 | QueryObserverResult<TData, TError>
640 | undefined
641​
642 const nextResult = this.createResult(this.#currentQuery, this.options)
643​
644 this.#currentResultState = this.#currentQuery.state
645 this.#currentResultOptions = this.options
646​
647 if (this.#currentResultState.data !== undefined) {
648 this.#lastQueryWithDefinedData = this.#currentQuery
649 }
650​
651 // Only notify and update result if something has changed
652 if (shallowEqualObjects(nextResult, prevResult)) {
653 return
654 }
655​
656 this.#currentResult = nextResult
657​
658 const shouldNotifyListeners = (): boolean => {
659 if (!prevResult) {
660 return true
661 }
662​
663 const { notifyOnChangeProps } = this.options
664 const notifyOnChangePropsValue =
665 typeof notifyOnChangeProps === 'function'
666 ? notifyOnChangeProps()
667 : notifyOnChangeProps
668​
669 if (
670 notifyOnChangePropsValue === 'all' ||
671 (!notifyOnChangePropsValue && !this.#trackedProps.size)
672 ) {
673 return true
674 }
675​
676 const includedProps = new Set(
677 notifyOnChangePropsValue ?? this.#trackedProps,
678 )
679​
680 if (this.options.throwOnError) {
681 includedProps.add('error')
682 }
683​
684 return Object.keys(this.#currentResult).some((key) => {
685 const typedKey = key as keyof QueryObserverResult
686 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
687​
688 return changed && includedProps.has(typedKey)
689 })
690 }
691​
692 this.#notify({ listeners: shouldNotifyListeners() })
693 }
694​
695 #updateQuery(): void {
696 const query = this.#client.getQueryCache().build(this.#client, this.options)
697​
698 if (query === this.#currentQuery) {
699 return
700 }
701​
702 const prevQuery = this.#currentQuery as
703 | Query<TQueryFnData, TError, TQueryData, TQueryKey>
704 | undefined
705 this.#currentQuery = query
706 this.#currentQueryInitialState = query.state
707​
708 if (this.hasListeners()) {
709 prevQuery?.removeObserver(this)
710 query.addObserver(this)
711 }
712 }
713​
714 onQueryUpdate(): void {
715 this.updateResult()
716​
717 if (this.hasListeners()) {
718 this.#updateTimers()
719 }
720 }
721​
722 #notify(notifyOptions: { listeners: boolean }): void {
723 notifyManager.batch(() => {
724 // First, trigger the listeners
725 if (notifyOptions.listeners) {
726 this.listeners.forEach((listener) => {
727 listener(this.#currentResult)
728 })
729 }
730​
731 // Then the cache listeners
732 this.#client.getQueryCache().notify({
733 query: this.#currentQuery,
734 type: 'observerResultsUpdated',
735 })
736 })
737 }
739​
740function shouldLoadOnMount(
741 query: Query<any, any, any, any>,
742 options: QueryObserverOptions<any, any, any, any>,
743): boolean {
744 return (
745 resolveEnabled(options.enabled, query) !== false &&
746 query.state.data === undefined &&
747 !(query.state.status === 'error' && options.retryOnMount === false)
748 )
750​
751function shouldFetchOnMount(
752 query: Query<any, any, any, any>,
753 options: QueryObserverOptions<any, any, any, any, any>,
754): boolean {
755 return (
756 shouldLoadOnMount(query, options) ||
757 (query.state.data !== undefined &&
758 shouldFetchOn(query, options, options.refetchOnMount))
759 )
761​
762function shouldFetchOn(
763 query: Query<any, any, any, any>,
764 options: QueryObserverOptions<any, any, any, any, any>,
765 field: (typeof options)['refetchOnMount'] &
766 (typeof options)['refetchOnWindowFocus'] &
767 (typeof options)['refetchOnReconnect'],
768) {
769 if (
770 resolveEnabled(options.enabled, query) !== false &&
771 resolveStaleTime(options.staleTime, query) !== 'static'
772 ) {
773 const value = typeof field === 'function' ? field(query) : field
774​
775 return value === 'always' || (value !== false && isStale(query, options))
776 }
777 return false
779​
780function shouldFetchOptionally(
781 query: Query<any, any, any, any>,
782 prevQuery: Query<any, any, any, any>,
783 options: QueryObserverOptions<any, any, any, any, any>,
784 prevOptions: QueryObserverOptions<any, any, any, any, any>,
785): boolean {
786 return (
787 (query !== prevQuery ||
788 resolveEnabled(prevOptions.enabled, query) === false) &&
789 (!options.suspense || query.state.status !== 'error') &&
790 isStale(query, options)
791 )
793​
794function isStale(
795 query: Query<any, any, any, any>,
796 options: QueryObserverOptions<any, any, any, any, any>,
797): boolean {
798 return (
799 resolveEnabled(options.enabled, query) !== false &&
800 query.isStaleByTime(resolveStaleTime(options.staleTime, query))
801 )
803​
804// this function would decide if we will update the observer's 'current'
805// properties after an optimistic reading via getOptimisticResult
806function shouldAssignObserverCurrentProperties<
807 TQueryFnData = unknown,
808 TError = unknown,
809 TData = TQueryFnData,
810 TQueryData = TQueryFnData,
811 TQueryKey extends QueryKey = QueryKey,
812>(
813 observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
814 optimisticResult: QueryObserverResult<TData, TError>,
815) {
816 // if the newly created result isn't what the observer is holding as current,
817 // then we'll need to update the properties as well
818 if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
819 return true
820 }
821​
822 // basically, just keep previous properties if nothing changed
823 return false