How to use @wry/equality - 7 common examples

To help you get started, we’ve selected a few @wry/equality examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / react-apollo / packages / hooks / src / data / QueryData.ts View on Github external
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);
      }
    }
  }
github apollographql / react-apollo / packages / hooks / src / data / QueryData.ts View on Github external
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);
      }
    }
  }
github apollographql / apollo-client / src / react / data / QueryData.ts View on Github external
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 => {
github apollographql / react-apollo / packages / hooks / src / data / QueryData.ts View on Github external
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();
        }
      }
    });
github apollographql / apollo-client / src / react / data / MutationData.ts View on Github external
private updateResult(result: MutationResult) {
    if (
      this.isMounted &&
      (!this.previousResult || !equal(this.previousResult, result))
    ) {
      this.setResult(result);
      this.previousResult = result;
    }
  }
}
github apollographql / react-apollo / packages / hooks / src / data / MutationData.ts View on Github external
private updateResult(result: MutationResult) {
    if (
      this.isMounted &&
      (!this.previousResult || !isEqual(this.previousResult, result))
    ) {
      this.setResult(result);
      this.previousResult = result;
    }
  }
}
github apollographql / react-apollo / packages / hooks / src / data / SubscriptionData.ts View on Github external
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 };
  }

@wry/equality

Structural equality checking for JavaScript values

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular @wry/equality functions

Similar packages