Last active
June 21, 2016 07:10
-
-
Save evturn/ff0f7bae270fe955a74ead8450c978a0 to your computer and use it in GitHub Desktop.
Inward React Nesting
This file contains hidden or 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
const { cloneElement } = React | |
const plopProps = plops => ( | |
props => ( | |
inward => ( | |
plops(props) | |
? cloneElement(plops(props), props, (plops(props).props.children || []).concat(inward.plops(props))) | |
: inward.plops(props) | |
) | |
) | |
) | |
const Inward = plops => { | |
return { | |
plops, | |
concat: inward => Inwardprops => plopProps(plops)(props)(inward)) | |
} | |
} | |
const plopReducer = (acc, x) => acc.concat(x) | |
const Name = ({ name }) => <span>{name} really enjoys </span> | |
const Activity = ({ activity }) => <em>{activity}.</em> | |
const App = [Name, Activity] | |
.map(Inward) | |
.reduce(plopReducer, Inward(_ => null)) | |
.plops | |
ReactDOM.render( | |
<App | |
name="Fred Estaircase" | |
activity="eating dolphins" | |
/>, | |
document.getElementById('container') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment