Ember.js Return Promises to ApplicationRoute When Configuring Multiple Controller Models

I need to install several controller models in the hook applicationRoute:

model: function() {    
    this.controllerFor('markets').set('model', this.store.pushPayload('market', marketsCache)); 
    this.controllerFor('pages').set('model', this.store.pushPayload('page', pagesCache)); 
    this.controllerFor('categories').set('model', this.store.pushPayload('category', categoriesCache)); 
    this.controllerFor('employees').set('model', this.store.pushPayload('employee', employeesCache));
}

In my webservers index.php file I set the variables javascript marketsCache, pagesCache, categoriesCacheand employeesCache. They are retrieved from the APC cache because the API intensively requires requests.

As you can see, I want the application to expect the model to be filled. However, promises are only for AJAX requests, as far as I know. So the question is, can these lines be wrapped controllerForin a promise?

+3
source share
2 answers

pushPayload , , all, , .

model: function() {    
    this.store.pushPayload('market', marketsCache);
    this.store.pushPayload('page', pagesCache)
    ....

    var market = this.store.all('market'),
        pages = this.store.all('page');
    ....

    this.controllerFor('markets').set('model', model.market); 
    this.controllerFor('pages').set('model', model.pages); 
    ....
}
+2

jQuery Deferred/When:

var market = this.store.pushPayload('market', marketsCache);
this.controllerFor('markets').set('model', market); 

var page = this.store.pushPayload('page', pagesCache);
this.controllerFor('pages').set('model', page); 

var category = this.store.pushPayload('category', categoriesCache);
this.controllerFor('categories').set('model', category); 

var employee = this.store.pushPayload('employee', employeesCache);
this.controllerFor('employees').set('model', employee);

return $.when(market, page, category, employee);

: https://api.jquery.com/jQuery.when/

0

All Articles