Skip to content

Commit bc094b4

Browse files
committed
More implementation comments in QueryInfo cache.watch listener.
1 parent d5463be commit bc094b4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/core/QueryInfo.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,23 @@ export class QueryInfo {
229229
if (oq) {
230230
oq["queryInfo"] = this;
231231
this.listeners.add(this.oqListener = () => {
232-
// If this.diff came from an optimistic transaction, deliver the current
233-
// cache data to the ObservableQuery, but don't perform a reobservation,
234-
// since oq.reobserveCacheFirst might make a network request, and we
235-
// don't want to trigger network requests for optimistic updates.
236232
const diff = this.getDiff();
237233
if (diff.fromOptimisticTransaction) {
234+
// If this diff came from an optimistic transaction, deliver the
235+
// current cache data to the ObservableQuery, but don't perform a
236+
// reobservation, since oq.reobserveCacheFirst might make a network
237+
// request, and we never want to trigger network requests in the
238+
// middle of optimistic updates.
238239
oq["observe"]();
239240
} else {
241+
// Otherwise, make the ObservableQuery "reobserve" the latest data
242+
// using a temporary fetch policy of "cache-first", so complete cache
243+
// results have a chance to be delivered without triggering additional
244+
// network requests, even when options.fetchPolicy is "network-only"
245+
// or "cache-and-network". All other fetch policies are preserved by
246+
// this method, and are handled by calling oq.reobserve(). If this
247+
// reobservation is spurious, isDifferentFromLastResult still has a
248+
// chance to catch it before delivery to ObservableQuery subscribers.
240249
oq.reobserveCacheFirst();
241250
}
242251
});

0 commit comments

Comments
 (0)