I almost posted this question on StackOverflow, but it’s more of an open question about Ember and design patterns, so here it is:
I’m trying to implement a shopping cart model with Ember and I’m having difficulties seeing a pattern on how this should be done.
Let’s say that I’m browsing a list of Products at a given route, and each product has an action on it so that I can add it to my cart.
Now, the cart has not necessarily been loaded yet since I might not have navigated to that route before.
My initial reaction was to define my cart route like this:
App.Router.map(function() {
this.resource('cart', { path: '/cart' }, function(){
this.route('add', { path: '/:product_id' })
)}
});
And then in the afterModel of the add route, I add the product to the carts model and finally redirect to the cart route.
The other idea I had in mind was to simply load the cart from the server, add the item, save the changes, and then navigate to the cart route (which then loads the cart).
I’m wondering which approach have you taken in the past, and what would be good practice in order to not have to fight against the framework.