Last active
August 29, 2015 14:27
-
-
Save Maxim-Filimonov/1fa3e78f0172dbe7fc6f to your computer and use it in GitHub Desktop.
Magic of Ramda maybes
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
createLogo() { | |
R.compose(R.map(function (v) { | |
return <img src={v}/> | |
}), R.pluck('logo'), RF.Maybe); | |
}, | |
defaultLogo() { | |
return undefined; | |
}, | |
render() { | |
if (!this.data.loading) { | |
return ( | |
<div className="ui container"> | |
<header style={this.style.header} className="ui centered grid"> | |
{this.createLogo(this.data.event).getOrElse(this.defaultLogo())} | |
</header> | |
{this.renderContent()} | |
</div> | |
) |
And holyshit:
what is wrong with syntax.. all you need is:
Maybe.from(this.data.which.can.return.nil).getOrElse(this.default).andThen(transformToDom)
Anyway, you need:
Compose(createDomForImg, Maybe(this.data.event).getOrElse(this.default))
That is called point free programMing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like getOrElse is in the wrong place: transformation to dom happens only if you have value out of the this.data.event