Making an API request even when data is in the store?

You can use store.all('user') to get the already loaded data:

App.ApplicationRoute = Ember.Route.extend({
  model: function() {
    // load all user data once, when app load
    return this.find('user');
  }
})

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://api.myapp.dev'
});

App.ApplicationSerializer = DS.ActiveModelSerializer.extend({});

App.UsersRoute = Em.Route.extend({
  model: function() {
      // because the data is already loaded by ApplicationRoute, just get the record cache
      return this.store.all('user');
  },

  setupController: function(controller, model) {
    controller.set('model', model);
  }
});
2 Likes