Created
May 3, 2016 06:07
-
-
Save sdtsui/462008cca41999b97ad7e0fe3b52d21c to your computer and use it in GitHub Desktop.
siteRow-fp.js
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
// @flow | |
import React from 'react'; | |
import styles from './SiteRow.css'; | |
import classnames from 'classnames'; | |
import _ from 'lodash/fp'; | |
import R from 'ramda'; | |
/** | |
* Vanilla JS | |
*/ | |
const _mapPropsToIds = (props: Object): string => { | |
let ids; | |
if (props.offerIDs) { | |
ids = props | |
.offerIDs | |
.map( id => id.toString()) | |
.join(", "); | |
} | |
let idText = `Offer ID(s): ${ids}`; | |
return idText; | |
} | |
/** | |
* Lodash-FP | |
*/ | |
const _mapPropsToIds = (props) => { | |
let ids; | |
if (props.offerIDs) { | |
let getStrings = _.compose( | |
_.map(_.toString), | |
_.property('offerIDs'), | |
); | |
ids = getStrings(props).join(", "); | |
} | |
let idText = `Offer ID(s): ${ids}`; | |
return idText; | |
} | |
/** | |
* Ramda | |
*/ | |
const _applyJoinWithSpacer = (spacer, array) => { | |
return array.join(spacer); | |
}; | |
const _mapPropsToIds = R.ifElse( | |
R.compose(R.is(Array), R.prop('offerIDs')), | |
R.curry( | |
R.compose( | |
R.concat('Offer ID(s): '), | |
R.curry(_applyJoinWithSpacer)(", "), | |
R.curry(R.map(R.toString)), | |
R.curry(R.prop('offerIDs')), | |
) | |
), | |
function() {return "...loading.";} | |
); | |
const SiteRow = (props) => { | |
let idText = _mapPropsToIds(props); | |
return ( | |
<div> | |
{idText} | |
</div> | |
); | |
} | |
export default SiteRow; |
Author
sdtsui
commented
May 3, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment