I’ve been thinking about something over the past week, and I wonder if this would solve the animation probem, and maybe a number of others as well. My thinking is to build on the conventions developed in the async model work and make actions support similar asyncronicity using promises.
Use Case
I have a paginated list of data and I want to have a sliding transition between pages. However, at the moment pages are not tied to routes, they are just in the controller. When I click the button for the next page, I’d like to do the following:
- Slide the current page out to the left
- Load the second page of data
- Slide the next page in from the right
I think this could be accomplished by having before
, after
and action
callbacks for each action. If any of the callbacks return a promise, the entire process will block until that promise resolves. So the next page action would like like:
Ember.Component.extend({
actions: {
nextPage: {
before: function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
this.$("#main-data").addClass("slide-out-left");
this.$("#main-data").on("webkitTransitionEnd", resolve);
});
},
action: function() {
this.loadNextPage();
},
after: function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
this.$("#main-data").addClass("slide-out-left");
this.$("#main-data").on("webkitTransitionEnd", resolve);
});
}
}
}
});
Of course, if I specify the action normally without the callback style it would work synchronously just like it does today. This would keep it backwards compatible with the current action
helper, but give the functionality to anyone who needs it.
I’m interested in working on this some more, but wanted to see what others think of this API. Would this be useful for other cases besides animation? Are there any upcoming changes to the action
helper that might conflict with this?