Last active
December 19, 2015 01:49
-
-
Save gunn/5879082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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