2019-01-31 01:04:11 +00:00
|
|
|
/** @format */
|
|
|
|
|
2019-02-13 11:44:58 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { isNil } from 'lodash';
|
|
|
|
|
2019-01-31 01:04:11 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { DEFAULT_REQUIREMENT } from '../constants';
|
|
|
|
|
2019-05-24 07:22:21 +00:00
|
|
|
const getSettings = ( getResource, requireResource ) => (
|
|
|
|
group,
|
|
|
|
requirement = DEFAULT_REQUIREMENT
|
|
|
|
) => {
|
|
|
|
return requireResource( requirement, `settings/${ group }` ).data || {};
|
2019-02-13 11:44:58 +00:00
|
|
|
};
|
|
|
|
|
2019-05-24 07:22:21 +00:00
|
|
|
const getSettingsError = getResource => group => {
|
|
|
|
return getResource( `settings/${ group }` ).error;
|
2019-02-13 11:44:58 +00:00
|
|
|
};
|
|
|
|
|
2019-05-24 07:22:21 +00:00
|
|
|
const isGetSettingsRequesting = getResource => group => {
|
|
|
|
const { lastReceived, lastRequested } = getResource( `settings/${ group }` );
|
2019-02-13 11:44:58 +00:00
|
|
|
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastRequested > lastReceived;
|
2019-01-31 01:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getSettings,
|
2019-02-13 11:44:58 +00:00
|
|
|
getSettingsError,
|
|
|
|
isGetSettingsRequesting,
|
2019-01-31 01:04:11 +00:00
|
|
|
};
|