Created
October 14, 2015 04:48
-
-
Save bfitch/102fe29a180dc8d8c00b to your computer and use it in GitHub Desktop.
computed stuff
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
// ConversationList.js | |
@Cerebral({}, { | |
conversations: ['decoratedConversations'] | |
}) | |
class ConversationList extends React.Component { | |
render() { | |
return ( | |
{this.props.conversations.map((conversation) => <Conversation key={conversation.uid} conversation={conversation}/>)} | |
); | |
} | |
} | |
//Conversation.js | |
class Conversation extends React.Component { | |
render() { | |
return ( | |
<div> | |
<div>{this.props.isNew ? "UNREAD" : "READ"}</div> | |
<div>{this.props.conversation.subject}</div> | |
</div> | |
); | |
} | |
} | |
// controller.js | |
const computed = { | |
isNew: function(get, getComputed) { | |
return (conversation) => { | |
return conversation.read_by_uids.every((uid) => { | |
uid !== getComputed(['currentPracticeUserUid']); | |
}); | |
}; | |
}, | |
decoratedConversations: function(get, getComputed) { | |
return get(['conversations']).map((conversation) => { | |
let clone = Object.assign({}, conversation); | |
clone.isNew = computed.isNew(get, getComputed)(conversation); | |
return clone; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment