Hey @seif, the short answer is that this doesn’t work this way in Ember. As I understand it, Ember’s action handlers only ever return true or false, and these boolean return values are used to determine whether handling the action “bubbles” to the next target up the chain. Even though actions sent from a component using sendAction do not bubble, they use the same action-handling code that the rest of ember uses, which coerces the return value to true or false.
Ember’s implementation of sendAction internally uses triggerAction. sendAction doesn’t actually return the result of triggerAction, but even if it did it would only be a boolean, as triggerAction only returns booleans.
I think the best way to do what you want to do here is to bind a property in the component to a property in its controlling context that changes asynchronously. If you needed to do some cleanup inside the component you could add an observer to that property, too.
@seif I’ve been thinking about something very similar lately. I spoke to @machty about it and he pointed me to a computed property that he’s been using.
// A PromiseAction is an action set on the controller,
// but not in the actions hash, which allows it to be
// passed in directly to the component. The component
// just sees it as a function that it can call that
// returns a promise. This is nice for when the component
// needs to emit some action that can fail; if it fails
// it can clean up after itself.
// Example:
// export default Controller.extend({
// setSomeValueAsyncly: promiseAction(function(newValue) {
// this.set('something', newValue);
// // simulate a slow set...
// return new Ember.RSVP.Promise(function(resolve) {
// Ember.run.later(resolve, 1000);
// });
// })
// });
//
// {{some-component on-change=setSomeValueAsyncly}}
export default function promiseActionComputedProperty(fn) {
return Ember.computed(function() {
var self = this;
return function() {
var args = arguments;
return new Ember.RSVP.Promise(function(resolve) {
resolve(fn.apply(self, args));
});
};
});
};
I’m looking at how I can use it myself but I just wanted to share.