woocommerce/plugins/woocommerce-admin/client/wc-api/settings/selectors.js

35 lines
748 B
JavaScript

/** @format */
/**
* External dependencies
*/
import { isNil } from 'lodash';
/**
* Internal dependencies
*/
import { DEFAULT_REQUIREMENT } from '../constants';
const getSettings = ( getResource, requireResource ) => ( requirement = DEFAULT_REQUIREMENT ) => {
return requireResource( requirement, 'settings' ).data || {};
};
const getSettingsError = getResource => () => {
return getResource( 'settings' ).error;
};
const isGetSettingsRequesting = getResource => () => {
const { lastRequested, lastReceived } = getResource( 'settings' );
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
return true;
}
return lastRequested > lastReceived;
};
export default {
getSettings,
getSettingsError,
isGetSettingsRequesting,
};