Created
November 25, 2017 11:41
-
-
Save ndelitski/9fc98aef94cd07eb3d28cd49fb31abb5 to your computer and use it in GitHub Desktop.
fp vs imperative
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
const mapSectionStatus = ({ section: { status, finished } }) => { | |
let statusLabel | |
let statusAppearance | |
if (status === SECTION_STATUS.needReview && finished) { | |
statusLabel = 'Edited' | |
} | |
if (status === SECTION_STATUS.needClarification && finished) { | |
statusLabel = 'Marked as resolved' | |
} | |
if (status === SECTION_STATUS.accepted && finished) { | |
statusLabel = 'Accepted' | |
statusAppearance = 'faded' | |
} | |
return { | |
status: statusLabel, | |
statusAppearance, | |
} | |
} |
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
const initialProps = { | |
status: 'accepted', | |
finished: true | |
} | |
const assocStatusLabel = cond([ | |
[where({status: equals('need_review'), finished: equals(true)}), assoc('statusLabel', 'Edited')], | |
[where({status: equals('need_clarify'), finished: equals(true)}), assoc('statusLabel', 'Marked as resolved')], | |
[where({status: equals('accepted'), finished: equals(true)}), assoc('statusLabel', 'Accepted')], | |
[R.T, obj => obj] | |
]) | |
const assocStatusAppearance = when( | |
where({status: equals('accepted'), finished: equals(true)}), | |
assoc('statusAppearance', 'faded') | |
) | |
pipe(assocStatusLabel, assocStatusAppearance)(initialProps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment