Last active
August 29, 2015 14:26
-
-
Save oliverbarnes/71ced4c6d334680f1c63 to your computer and use it in GitHub Desktop.
Computed property with promise not working
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
import Ember from 'ember'; | |
var PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); | |
export default Ember.Component.extend({ | |
proposal: null, | |
participant: null, | |
// previousSupport: [], | |
actions: { | |
toggleSupport: function(proposal, participant){ | |
this.set('proposal', proposal); | |
this.set('participant', participant); | |
var previousSupportQuery = { | |
query: { | |
filter: { | |
proposal_id: this.get('proposal.id'), | |
participant_id: this.get('participant.id') | |
} | |
} | |
}; | |
var self = this | |
this.container.lookup('service:supports').find(previousSupportQuery).then(function(resources) { | |
if( Ember.isEmpty(resources) ) { | |
self.addSupport(); | |
} else { | |
self.removeSupport(resources); | |
} | |
}); | |
} | |
}, | |
addSupport: function() { | |
var support = this.container.lookupFactory('model:supports').create(); | |
support.addRelationship('proposal', this.get('proposal.id')); | |
support.addRelationship('participant', this.get('participant.id')); | |
this.store.createResource('support', support); | |
}, | |
removeSupport: function(resources) { | |
this.store.deleteResource('support', resources.get('firstObject')); | |
} | |
// alreadySupported: Ember.computed('proposal.id', function() { | |
// return !Ember.isEmpty(this.get('previousSupport')); | |
// }), | |
// | |
// previousSupport: Ember.computed('proposal.id', 'participant.id', function() { | |
// var query = { | |
// query: { | |
// filter: { | |
// proposal_id: this.get('proposal.id'), | |
// participant_id: this.get('participant.id') | |
// } | |
// } | |
// }; | |
// | |
// return PromiseObject.create({ | |
// promise: this.container.lookup('service:supports').find(query) | |
// }); | |
// }) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as mentioned in slack
return !Ember.isEmpty(this.previousSupport);
needs to usethis.get
like soreturn !Ember.isEmpty(this.get('previousSupport'));