Skip to content

Commit

Permalink
Call this.currentObservable.tearDownQuery more consistently (#7259)
Browse files Browse the repository at this point in the history
Follow-up to #7205, per my comment in #7254:
#7254 (comment)

Instead of tearing down this.currentObservable only when
this.getOptions().skip is true in QueryData#removeQuerySubscription, I
split the tear-down functionality into a separate private method
(QueryData#removeObservable), which is now called everywhere
removeQuerySubscription is called, except in resubscribeToQuery, where we
specifically want to preserve this.observableQuery.
  • Loading branch information
benjamn committed Oct 30, 2020
1 parent 64e364f commit d14cf0e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/react/data/QueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class QueryData<TData, TVariables> extends OperationData {
const { skip, query } = this.getOptions();
if (skip || query !== this.previous.query) {
this.removeQuerySubscription();
this.removeObservable(!skip);
this.previous.query = query;
}

Expand Down Expand Up @@ -107,7 +108,7 @@ export class QueryData<TData, TVariables> extends OperationData {

public cleanup() {
this.removeQuerySubscription();
delete this.currentObservable;
this.removeObservable(true);
delete this.previous.result;
}

Expand Down Expand Up @@ -471,8 +472,15 @@ export class QueryData<TData, TVariables> extends OperationData {
if (this.currentSubscription) {
this.currentSubscription.unsubscribe();
delete this.currentSubscription;
} else if (this.currentObservable && this.getOptions().skip) {
}
}

private removeObservable(andDelete: boolean) {
if (this.currentObservable) {
this.currentObservable["tearDownQuery"]();
if (andDelete) {
delete this.currentObservable;
}
}
}

Expand Down

0 comments on commit d14cf0e

Please sign in to comment.