Created
March 22, 2017 06:27
-
-
Save andreychev/a38f9e9329129d41c6016dcd06b3512d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react'; | |
import Constants from 'cx-api/constants'; | |
import Loading from 'ux/flow/Loading'; | |
function isPending(loadingComponent) { | |
function pendingHOC({ status, loading = {}, children }) { | |
if (status === Constants.STATE_PENDING) { | |
return (<loadingComponent { ...loading } />); | |
} | |
return children || null; | |
} | |
pendingHOC.propTypes = { | |
status: PropTypes.oneOf([ | |
'', | |
Constants.STATE_PENDING, | |
Constants.STATE_RESOLVED, | |
Constants.STATE_REJECTED | |
]), | |
loading: PropTypes.object | |
}; | |
return pendingHOC; | |
} | |
export { isPending }; | |
export default isPending(Loading); |
import React, { PropTypes } from 'react';
import isEmpty from 'lodash/isEmpty';
import isNil from 'lodash/isNil';
import Empty from 'ux/flow/Empty';
function defaultIsExist({ data }) {
return !isNil(data) && !isEmpty(data);
}
function isExisting(emptyComponent) {
function existingHOC(props, isExist = defaultIsExist) {
const {
empty = {},
children
} = props;
if (isExist(props)) {
return children || null;
}
return (<emptyComponent { ...empty } />);
}
existingHOC.propTypes = {
empty: PropTypes.object
};
return existingHOC;
}
export { isExisting };
export default isExisting(Empty);
import React, { PropTypes } from 'react';
import Constants from 'cx-api/constants';
import Incident from 'ux/flow/Incident';
function isRejecting(rejectingComponent) {
function rejectingHOC({ status, rejecting = {}, children }) {
if (status === Constants.STATE_REJECTED) {
return (<rejectingComponent { ...rejecting } />);
}
return children || null;
}
rejectingHOC.propTypes = {
status: PropTypes.oneOf([
'',
Constants.STATE_PENDING,
Constants.STATE_RESOLVED,
Constants.STATE_REJECTED
]),
rejecting: PropTypes.object
};
return rejectingHOC;
}
export { isRejecting };
export default isRejecting(Incident);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same↑
But I don't like: https://github.com/acdlite/recompose/blob/b8466a6f40151b35095e8e3f56779846ae1ae682/src/packages/recompose/branch.js#L17.