lundi 30 janvier 2017

Fine-tune refreshing of multiple models in Ember route

There's a well known approach to support loading more than one model promise in an Ember route, using Ember.RSVP.hash:

// app/routes/posts.js

export default Ember.Route.extend({

  model(params) {
    return Ember.RSVP.hash({
      posts: this.store.findAll('post', params),
      tags: this.store.findAll('tag', params),
    });
  },

});

Now I have a page param, to be able to load the posts in batches, instead of loading them and showing them all at once. But page changes do not alter the tags. However, when the page param changes, the whole model of the route is triggered again to re-load, causing the app to re-fetch both the posts for the new page, and the same tags all over again.

Is there a way to fine-tune this so that the tags are not loaded when certain params change?




Aucun commentaire:

Enregistrer un commentaire