Skip to content

Instantly share code, notes, and snippets.

@bfitch
Created October 14, 2015 04:48
Show Gist options
  • Save bfitch/102fe29a180dc8d8c00b to your computer and use it in GitHub Desktop.
Save bfitch/102fe29a180dc8d8c00b to your computer and use it in GitHub Desktop.
computed stuff
// 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