Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oliverbarnes/71ced4c6d334680f1c63 to your computer and use it in GitHub Desktop.
Save oliverbarnes/71ced4c6d334680f1c63 to your computer and use it in GitHub Desktop.
Computed property with promise not working
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)
// });
// })
});
@pixelhandler
Copy link

as mentioned in slack return !Ember.isEmpty(this.previousSupport); needs to use this.get like so return !Ember.isEmpty(this.get('previousSupport'));

@oliverbarnes
Copy link
Author

@pixelhandler just went with a callback after the find() for now, not that bad in the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment