ember.js - How to load Ember Data data when app starts? -


as follow another question (i think 1 more specific) i'd ask how can load data when app starts. need cache strategy.

the data presented in our internal app refreshed once week don't want make new request every time user enters route (now see lot of ajax requests moving around app).

the .all() method resolve problem first have load data.

where else can load data accessible controller , templates? possible load data when app starts , pass controller model , controllerfor hooks?

in opinion there's no problem user has refresh app once week - maybe can change later.

my understanding of intuitivepixel answer

first load data 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 cache (store)

app.someroute = ember.route.extend   setupcontroller: (controller, model) ->     @controllerfor('user').set 'content', app.user.all()     # though can access properties via console data not visible in template     @controllerfor('currentuser').set 'content', app.user.all().objectat(0)     @controllerfor('top').set 'content', app.top.all() 

for example though can access avatar source with:

app.currentuser.all().objectat(0).get('gravatar') 

it not visible in template

{{#linkto 'users' classnames="avatar pull-left" title="back"}}   {{avatar gravatar}} {{/linkto}} 

i tried content.gravatar or controler.gravatar no success. the rest visible in view

only conceptually this:

app = ember.application.create({   // load data once , set somewhere accessible   ready: function() {     this.set('supermodelcache', app.supermodel.find());   } });   // define special model app.supermodel = ds.model.extend({   prop1: ds.attr('string'),   prop2: ds.attr('string'),   ... });  // , in routes need data cache // app.myfirstroute = ember.route.extend({   model: function () {     return app.get('supermodelcache.prop1');   } });  // , on... app.mysecondroute = ember.route.extend({   model: function () {     return app.get('supermodelcache.prop2');   } }); 

or in routes this:

// , in routes need data cache // app.myfirstroute = ember.route.extend({   model: function () {     return app.supermodel.all().get('prop1');   } });  // , on... app.mysecondroute = ember.route.extend({   model: function () {     return app.supermodel.all().get('prop2');   } }); 

this issue request on application start, reload data intervall/polling along application lifetime.

if application relies on data start @ all, call app.deferreadiness(); , counterpart app.advancereadiness(); when done, see here api docs reference: http://emberjs.com/api/classes/ember.application.html#method_deferreadiness

hope helps


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -