If the user is visiting a route for the first time, it makes sense to make them wait for the models to load. However once that route has already loaded its models, if the user visits again we wanted to render the template immediately with the loaded (stale) models, and silently refresh them in the background if necessary. This is what we came up with:
App.TeamsRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
var teams = this.store.find('team', {is_archived: false});
if(!controller.get('content.length')) {
// loadable mixin sets isLoading=true until model resolves
// useful for rendering template immediately,
// and showing a loading spinner where models will appear
controller.load(teams);
} else {
teams.then(function() {
// only update if changed
if(controller.get('content') !== teams) {
controller.set('content', teams);
}
});
}
}
This seems like a very common scenario useful especially with arrayControllers that have large models. So my question is this:
What is this concept called and are there any existing mixins / implementations of it for ember.js?
Aucun commentaire:
Enregistrer un commentaire