Skip to content

Commit

Permalink
DRY plugin fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Snook committed Nov 16, 2017
1 parent 8d4fab1 commit 4dc1307
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions client/extensions/woocommerce/app/settings/taxes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ class SettingsTaxes extends Component {
taxJarPluginActive: PropTypes.bool,
};

componentDidMount = () => {
const { isRequestingSitePlugins, siteId, sitePluginsLoaded } = this.props;
maybeFetchPlugins = props => {
const { isRequestingSitePlugins, siteId, sitePluginsLoaded } = props;

if ( siteId && ! isRequestingSitePlugins && ! sitePluginsLoaded ) {
this.props.fetchPlugins( [ siteId ] );
}
};

componentWillReceiveProps = newProps => {
const { isRequestingSitePlugins, siteId, sitePluginsLoaded } = newProps;
componentDidMount = () => {
this.maybeFetchPlugins( this.props );
};

if ( siteId && ! isRequestingSitePlugins && ! sitePluginsLoaded ) {
this.props.fetchPlugins( [ siteId ] );
}
componentWillReceiveProps = newProps => {
this.maybeFetchPlugins( newProps );
};

render = () => {
Expand Down
14 changes: 7 additions & 7 deletions client/extensions/woocommerce/app/settings/taxes/taxes-rates.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ class TaxesRates extends Component {
siteId: PropTypes.number.isRequired,
};

componentDidMount = () => {
const { address, loadedSettingsGeneral, loadedTaxRates, siteId } = this.props;
maybeFetchRates = props => {
const { address, loadedSettingsGeneral, loadedTaxRates, siteId } = props;

if ( loadedSettingsGeneral && ! loadedTaxRates ) {
this.props.fetchTaxRates( siteId, address );
}
};

componentDidMount = () => {
this.maybeFetchRates( this.props );
};

componentWillReceiveProps = nextProps => {
if ( nextProps.loadedSettingsGeneral ) {
if ( ! nextProps.loadedTaxRates ) {
this.props.fetchTaxRates( nextProps.siteId, nextProps.address );
}
}
this.maybeFetchRates( nextProps );
};

renderInfo = () => {
Expand Down

0 comments on commit 4dc1307

Please sign in to comment.