Skip to content

Instantly share code, notes, and snippets.

@ndelitski
Created November 25, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndelitski/9fc98aef94cd07eb3d28cd49fb31abb5 to your computer and use it in GitHub Desktop.
Save ndelitski/9fc98aef94cd07eb3d28cd49fb31abb5 to your computer and use it in GitHub Desktop.
fp vs imperative
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,
}
}
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