Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private handleErrorOrCompleted() {
const obsQuery = this.currentObservable.query;
if (!obsQuery) return;
const { data, loading, error } = obsQuery.getCurrentResult();
if (!loading) {
const { query, variables, onCompleted, onError } = this.getOptions();
// No changes, so we won't call onError/onCompleted.
if (
this.previousOptions &&
!this.previousData.loading &&
isEqual(this.previousOptions.query, query) &&
isEqual(this.previousOptions.variables, variables)
) {
return;
}
if (onCompleted && !error) {
onCompleted(data);
} else if (onError && error) {
onError(error);
}
}
}
private handleErrorOrCompleted() {
const obsQuery = this.currentObservable.query;
if (!obsQuery) return;
const { data, loading, error } = obsQuery.getCurrentResult();
if (!loading) {
const { query, variables, onCompleted, onError } = this.getOptions();
// No changes, so we won't call onError/onCompleted.
if (
this.previousOptions &&
!this.previousData.loading &&
isEqual(this.previousOptions.query, query) &&
isEqual(this.previousOptions.variables, variables)
) {
return;
}
if (onCompleted && !error) {
onCompleted(data);
} else if (onError && error) {
onError(error);
}
}
}
next: ({ loading, networkStatus, data }) => {
const previousResult = this.previousData.result;
// Make sure we're not attempting to re-render similar results
if (
previousResult &&
previousResult.loading === loading &&
previousResult.networkStatus === networkStatus &&
isEqual(previousResult.data, data)
) {
return;
}
this.forceUpdate();
},
error: error => {
error: error => {
this.resubscribeToQuery();
if (!error.hasOwnProperty('graphQLErrors')) throw error;
const previousResult = this.previousData.result;
if (
(previousResult && previousResult.loading) ||
!isEqual(error, this.previousData.error)
) {
this.previousData.error = error;
this.forceUpdate();
}
}
});
private updateResult(result: MutationResult) {
if (
this.isMounted &&
(!this.previousResult || !equal(this.previousResult, result))
) {
this.setResult(result);
this.previousResult = result;
}
}
}
private updateResult(result: MutationResult) {
if (
this.isMounted &&
(!this.previousResult || !isEqual(this.previousResult, result))
) {
this.setResult(result);
this.previousResult = result;
}
}
}
let currentResult = result;
if (this.refreshClient().isNew) {
currentResult = this.getLoadingResult();
}
let { shouldResubscribe } = this.getOptions();
if (typeof shouldResubscribe === 'function') {
shouldResubscribe = !!shouldResubscribe(this.getOptions());
}
if (
shouldResubscribe !== false &&
this.previousOptions &&
Object.keys(this.previousOptions).length > 0 &&
(this.previousOptions.subscription !== this.getOptions().subscription ||
!isEqual(this.previousOptions.variables, this.getOptions().variables) ||
this.previousOptions.skip !== this.getOptions().skip)
) {
this.cleanup();
currentResult = this.getLoadingResult();
}
this.initialize(this.getOptions());
this.startSubscription();
this.previousOptions = this.getOptions();
return { ...currentResult, variables: this.getOptions().variables };
}