Since Ember.Data 1.0 Beta we have to use store.find('model') instead App.Model.find(). How to get access to store object inside App object?
var App = Ember.Application.create({
auth: function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
// ... get token somehow ...
// how to get store?
this.store.find('user').then(function(users) {
App.set('user', users.get('firstObject');
resolve();
}, function(err) {
reject();
});
});
}
});
App.deferReadiness();
App.auth().then(App.advanceReadiness());
You can create an initializer that injects the store into the application object.
App.initializer({
name: 'Inject Store',
initialize: function(container, application) {
container.injection('application:main', 'store', 'store:main');
}
});
Afterwards you can use this.get('store') in the application. Of course you can circumvent the container by simply setting the store (retrieved via container.lookUp) on the application object, but that defeats the purpose of the container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With