Skip to content

Instantly share code, notes, and snippets.

@serenaf
Created November 7, 2017 10:27
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 serenaf/d9d7fc55753d929f5ee570a9620f44c4 to your computer and use it in GitHub Desktop.
Save serenaf/d9d7fc55753d929f5ee570a9620f44c4 to your computer and use it in GitHub Desktop.
Item Model Computed Property
import DS from 'ember-data';
import { computed } from '@ember/object';
export default DS.Model.extend({
title: DS.attr('string'),
points: DS.attr('number'),
time: DS.attr('unix-date'),
timeAgo: DS.attr('string'),
url: DS.attr('string'),
domain: DS.attr('string'),
isInternalLink: computed.empty('domain'),
externalUrl: computed('domain', 'isInternalLink', function() {
if (this.get('isInternalLink')) {
return `https://news.ycombinator.com/item?id=${this.get('id')}`
}
return this.get('url');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment