Skip to content

Instantly share code, notes, and snippets.

@manufaktor
Last active December 30, 2015 08:19
Show Gist options
  • Save manufaktor/7801986 to your computer and use it in GitHub Desktop.
Save manufaktor/7801986 to your computer and use it in GitHub Desktop.
Poor man's colletions in ember.js
App = Ember.Application.create({
collections: Ember.Object.create({
products: null
})
});
App.set("collections.products", Ember.ArrayProxy.create({
content: [],
all: function(params){
var collection = this;
return apiGET("/products", params).then(function(products){
return collection.set("content", products.map(function(product){
return App.Product.create(product);
}));
});
},
findById: function(id){
return apiGET("/products/" + id).then(function(product){
return App.Product.create(product);
});
}
}));
App.ProductsRoute = Ember.Route.extend({
model: function(){
return App.get("collections.products").all()
}
});
App.ProductRoute = Ember.Route.extend({
model: function(params){
return App.get("collections.products").findById(params.productId)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment