Skip to content

Instantly share code, notes, and snippets.

@IronGremlin
Last active September 9, 2016 00:37
Show Gist options
  • Save IronGremlin/eb09738437bb572cfc73d984f20ffbab to your computer and use it in GitHub Desktop.
Save IronGremlin/eb09738437bb572cfc73d984f20ffbab to your computer and use it in GitHub Desktop.
functional React
"use strict";
function ReactFunctor(tag,attr,props,children){
let classArgs = {
render : function render() {
return React.createElement(tag,this.props,this.props.children);
}
};
if (props !== null) Object.assign(classArgs,props);
return React.createElement(React.createClass(classArgs),attr,children);
};
var candidates = [
{ id: 44, firstName: 'barrack', lastName: 'obama' },
{ id: 43, firstName: 'george', lastName: 'bush' },
{ id: 42, firstName: 'bill', lastName: 'clinton' },
{ id: 45, firstName: 'hillary', lastName: null },
{ id: 40, firstName: 'ronald', lastName: 'reagan' }
];
function candidateParser(item){
let curriedFunctor = R.curry(ReactFunctor),
fetchName = R.pipe(R.props(['firstName','lastName']),R.join(' '),R.trim,R.toUpper),
fetchArgs = R.compose(R.assoc('key',R.__,{href : '#',className : 'collection-item'}),(R.prop('id')));
R.converge(curriedFunctor,[f=>'a',fetchArgs,f=>null,fetchName])(item);
}
var outElement = ReactFunctor('div',{className : 'collection', id:'target'},null,candidates.map(candidateParser));
ReactDOM.render(outElement,mountNode);
@IronGremlin
Copy link
Author

Added rambda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment