Default store (w/o Ember Data)


Hello there. I’m doing some research of the bowels of Ember, and I have a question about how @ember/routing/route implements store.

I understand this implementation is normally expected to be overriden by Ember Data or what have you, and that it’s considered legacy, but still I’d like to know about the history of it.

So specifically: why this line?

modelClass = modelClass.class;

From what I can see, all it achieves is to throw the container out of the window (as the result of .class won’t have access to the container), which limits the usefulness of the result at all, if I understand correctly.

Thank you!


Someone with some more Ember knowledge might be able to provide a better answer… but I’ll try my best.

In the old days of Ember Data (1.x) we would fetch data using the model’s class.

// Ember Data 1.x style of data fetching

In Ember 2.12 the factoryFor API was added. This API returns an object with two properties, create and class. The class property points back to the original class…

let Person = DS.Model.extend();
owner.register('model:person', Person);
let factory = owner.factoryFor('model:person');
factory.class === Person; // true
let alice = factory.create();

So if you wanted to call Person.find() you would need to first lookup the factory and then access the class property. Hence, modelClass.class

Check out the factoryFor RFC, it’s got some great examples!


Thank you! That explains some of it, and provides useful pointers for further research. I’ll return with more questions when I get stuck again :smile: