Created
December 21, 2016 19:01
-
-
Save davelowensohn/2b85b003c3c4a310e94bac64c02d835f to your computer and use it in GitHub Desktop.
Ember layered async model RSVP hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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