Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Last active October 15, 2015 22:34
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 samselikoff/c2b27bb3fa81b229be6f to your computer and use it in GitHub Desktop.
Save samselikoff/c2b27bb3fa81b229be6f to your computer and use it in GitHub Desktop.
Declarative CPs in Ember (c/o ryanto)
import Ember from 'ember';
export default Ember.Component.extend({
channelTalk: null,
talk: null,
channel: Ember.computed.readOnly('channelTalk.channel'),
tagName: 'tr',
classNames: 'Channel-table-row',
confirmRemoveChannelTalkAction: "confirmRemoveChannelTalk",
hasTalkMedia: Ember.computed.bool('talk.media'),
hasTalkContext: Ember.computed.bool('talk.talkContext'),
primaryPhoto: Ember.computed.readOnly('talk.primaryTalkPhoto'),
hasPrimaryPhoto: Ember.computed.bool('talk.primaryTalkPhoto'),
expectedAspectRatios: Ember.computed.readOnly('channel.aspectRatios'),
photoSizes: Ember.computed.readOnly('primaryPhoto.photoSizes'),
photoSizeAspectRatios: Ember.computed.mapBy('photoSizes', 'apsectRatio'),
missingAspectRatios: Ember.computed.setDiff(
'expectedAspectRatios',
'photoSizeAspectRatios'
),
hasAllAspectRatios: Ember.computed.equal('missingAspectRatios.length', 0),
speakers: Ember.computed.readOnly('talk.speakers'),
symfonySpeakers: Ember.computed.filterBy('speakers', 'isSymfonySpeaker'),
nonSymfonySpeakers: Ember.computed.setDiff('speakers', 'symfonySpeakers'),
hasAllSymfonySpeakers: Ember.computed.equal('nonSymfonySpeakers.length', 0),
canPublishTalk: Ember.computed.and(
'hasTalkMedia',
'hasTalkContext',
'hasPrimaryPhoto',
'hasAllAspectRatios',
'hasAllSymfonyspeakers'
),
cannotPublishTalk: Ember.computed.not('canPublishTalk'),
actions: {
confirmRemoveChannelTalk() {
const channelTalk = this.get('channelTalk.content');
this.sendAction('confirmRemoveChannelTalkAction', channelTalk);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment