What can I return from the model hook in routes?

Hey everyone, I’m new to Ember and I was wondering how the model hook works in routes. I’ve seen various tutorials using the model hook differently. Some will have it return static data. Others will return the promise from a $.getJSON() call. Others will return the promise from Ember.$.getJSON(). And some will use Ember Data.

How does Ember.$ differ from $/jQuery? Is it modifying the promise to be an RSVP promise instead of a jQuery promise? Does Ember Data use RSVP promises?

I’ve tried googling this and every result that comes up is “Angular vs Ember” so I thought I’d ask here. Thanks!

Ember.$ is an alias to the jQuery object: https://github.com/emberjs/ember.js/blob/v1.12.0/packages/ember-views/lib/main.js#L53

http://emberjs.com/api/classes/Ember.Route.html#method_model says the return value of the model hook is an Object or Promise

the model for this route. If a promise is returned, the transition will pause until the promise resolves, and the resolved value of the promise will be used as the model for this route.

(Object in this case means anything synchronous)

btw if you want to use $.getJSON or $.ajax I would recommend GitHub - instructure/ic-ajax: ember-friendly jQuery.ajax wrapper which is an wrapper around the jQuery functions that works with the Ember run loop


Thanks! That cleared up a lot.