Created
September 11, 2014 16:36
-
-
Save samselikoff/771ca536dc19d609d445 to your computer and use it in GitHub Desktop.
Cleaning up code with Ember.computed
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
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