Skip to content

Instantly share code, notes, and snippets.

@davelowensohn
Created December 21, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelowensohn/2b85b003c3c4a310e94bac64c02d835f to your computer and use it in GitHub Desktop.
Save davelowensohn/2b85b003c3c4a310e94bac64c02d835f to your computer and use it in GitHub Desktop.
Ember layered async model RSVP hash
model(params){
var allProds = this.store.findAll('product'),
brandsPromise = allProds.then(allProducts => {
var allBrands = allProducts.map( aProd => aProd.get('vendor')),
filteredBrandPromise = new Promise(function (resolve, reject){
resolve( Array.from(new Set(allBrands)).sort());
reject();
});
return filteredBrandPromise;
}
);
return Ember.RSVP.hash({
allCategories: this.store.findAll('product-category'),
allProducts: allProds,
selectedFilterCategory: (params.categoryId) ? this.store.findRecord('product-category', params.categoryId) : null,
selectedFilterBrand: (params.brand) ? params.brand : null,
allBrands: brandsPromise
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment