As a follow up to my another question (I think this one is more specific) I'd like to ask you how can I load data when an app starts. I need some cache strategy.
The data that is presented in our internal app is refreshed once a week so that I don't want to make a new request every time a user enters a route (now I see a lot of ajax requests moving around the app).
the .all() method would probably resolve my problem but first I have to load the data.
Where else can I load data that would be accessible to controller and then templates? Is it possible to load data when an app starts and pass it to a controller as you does with the model
and controllerFor
hooks?
In my opinion there's no problem that a user has to refresh the app once a week - maybe we can change that later.
my understanding of intuitivepixel answer
First load data from the server:
App = Ember.Application.create({
ready: function() {
this.set('userCache', App.User.find());
this.set('currentUserCache', App.User.find(1));
this.set('topCache', App.Top.find());
}
});
Then load data from cache (store)
App.SomeRoute = Ember.Route.extend
setupController: (controller, model) ->
@controllerFor('user').set 'content', App.User.all()
# though I can access its properties via console data is not visible in the template
@controllerFor('currentUser').set 'content', App.User.all().objectAt(0)
@controllerFor('top').set 'content', App.Top.all()
For example though I can access avatar source with:
App.CurrentUser.all().objectAt(0).get('gravatar')
it is not visible in the template
{{#linkTo 'users' classNames="avatar pull-left" title="back"}}
{{avatar gravatar}}
{{/linkTo}}
I also tried with content.gravatar
or controler.gravatar
but to no success.
The rest is visible in the view