lundi 16 février 2015

Move duplicated routes code in emberjs

I have to very similar routes:





App.DiscountRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
categories: this.store.findAll('discountCategory'),
discounts: this.store.findAll('discount'),
total_size: 6
});
}
});



and





App.CategoryRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('discount');
},
model: function(params) {
return Ember.RSVP.hash({
categories: this.store.findAll('discountCategory'),
discounts: this.store.filter('discount',function(discount) {
return discount.get('discountCategory').get('id')==params.category_id
}),
total_size: 6
});
}
});



Where should I place categories model and total_size counter, which will be available from any routes in my application?





Aucun commentaire:

Enregistrer un commentaire