Skip to content

Instantly share code, notes, and snippets.

@gunn
Last active December 19, 2015 01:49
Show Gist options
  • Save gunn/5879082 to your computer and use it in GitHub Desktop.
Save gunn/5879082 to your computer and use it in GitHub Desktop.
// Load the light version of all subjects on page load
App.ApplicationController = Em.Controller.extend({
init: function() {
return App.Subject.find();
}
});
// Fetch all our previously loaded subjects
App.SubjectsRoute = Ember.Route.extend({
model: function() {
return App.Subject.all();
}
});
App.SubjectRoute = Ember.Route.extend({
// If we're loading the page directly to this route, do a normal find
model: function(params) {
return App.Subject.find(params.subject_id);
},
setupController: function(controller, model) {
// Show what details we have for this subject (e.g. the title) immediately
controller.set("model", model);
// Load full details for the model and display them as soon as they arrive
if (Em.isEmpty(model.get("text"))) {
App.Subject.find(model.get("id")).then(function(model) {
return controller.set("model", model);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment