loadDataIfNeeded()

in src/amo/pages/AddonReviewList/index.js [108:157]


  loadDataIfNeeded(prevProps?: InternalProps) {
    const lastAddon = prevProps && prevProps.addon;
    const {
      addon,
      addonIsLoading,
      areReviewsLoading,
      dispatch,
      errorHandler,
      location,
      match: {
        params: { addonSlug },
      },
      reviews,
    } = this.props;

    if (errorHandler.hasError()) {
      log.warn('Not loading data because of an error');
      return;
    }

    if (!addon) {
      if (!addonIsLoading) {
        dispatch(
          fetchAddon({
            showGroupedRatings: true,
            slug: addonSlug,
            errorHandler,
          }),
        );
      }
    } else if (
      // This is the first time rendering the component.
      !prevProps ||
      // The component is getting updated with a new addon type.
      (addon && lastAddon && addon.type !== lastAddon.type)
    ) {
      dispatch(setViewContext(addon.type));
    }

    if (!areReviewsLoading && !reviews) {
      dispatch(
        fetchReviews({
          addonSlug,
          errorHandlerId: errorHandler.id,
          page: getCurrentPage(location),
          score: location.query.score || null,
        }),
      );
    }
  }