Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Created September 11, 2014 16:36
Show Gist options
  • Save samselikoff/771ca536dc19d609d445 to your computer and use it in GitHub Desktop.
Save samselikoff/771ca536dc19d609d445 to your computer and use it in GitHub Desktop.
Cleaning up code with Ember.computed
device: DS.belongsTo('device'),
- isNotIngestable: function() {
- return Ember.isNone(this.get('device'));
- }.property('device'),
-
- isScanning: function() {
- var device = this.get('device');
- var deviceIsConnected = !Ember.isNone(device);
- var deviceHasntFoundFiles = device && Ember.isNone(device.get('files'));
-
- return (deviceIsConnected && deviceHasntFoundFiles);
- }.property('device', 'device.files'),
-
- isEmpty: function() {
- var device = this.get('device');
- var deviceIsConnected = !Ember.isNone(device);
- var deviceHasNoFiles = device && device.get('hasNoFiles');
-
- return deviceIsConnected && deviceHasNoFiles;
- }.property('device.files'),
-
- isIngestable: function() {
- var device = this.get('device');
- var deviceIsConnected = !Ember.isNone(device);
- var deviceHasFiles = device && device.get('hasFiles');
- var deviceHasNoIngest = device && Ember.isNone(device.get('ingest'));
-
- return deviceIsConnected && deviceHasFiles && deviceHasNoIngest;
- }.property('device.files', 'device.ingest'),
+ hasNoDevice: Ember.computed.none('device'),
+ deviceIsConnected: Ember.computed.not('hasNoDevice'),
+ hasNoIngest: Ember.computed.none('ingest'),
+
+ isNotIngestable: Ember.computed.alias('hasNoDevice'),
+ isScanning: Ember.computed.alias('device.scanningForFiles'),
+ isEmpty: Ember.computed.alias('device.hasNoFiles'),
+ isIngestable: Ember.computed.and('device.hasFiles', 'hasNoIngest'),
state: function() {
if (this.get('isNotIngestable')) {return 'not-ingestable';}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment