Examples should include the example in the demo.
I was trying so many different combinations of making promises and returning them in the action... I discovered in the demo, a callback is used.
http://jsbin.com/qokogasilu/1/edit?html,css,js,output
so, in my code, I now have this:
actions: {
// callback required for async button
register(callback) {
this.get('pathStore').storeCurrentRoute();
let promise = this.get('model').save().then(user => {
this.sendAction('successAction');
user.unloadRecord();
});
callback(promise);
},
},
and now my async-button correctly stops being in the pending state upon promise return (presumably -- it's still unclear why there needs to be a callback with a promised passed - esp since this is an anti-pattern in ember).
This is probably too late to answer but I was stumbling on this too, I think your code should be more like:
actions: {
// callback required for async button
register(callback) {
this.get('pathStore').storeCurrentRoute();
const promise = new Ember.RSVP.Promise(function(resolve, reject) {
this.get('model').save().then(() => {
this.sendAction('successAction');
user.unloadRecord();
Ember.run.later(function() {
resolve();
});
}).catch((reason) => {
Ember.run.later(function() {
reject();
});
});
};
callback(promise);
},
},
It's never too late. :-).
Why the run.later? would that make the button stay spinning longer than the request? (a request is only being made on save.
Not super proficient in Ember yet, run.later helped for a use case I had, I guess you can do resolve/reject directly?