list
property
Returns the data in its typed list form.
connection.list( listInstanceData, set )
Takes an object with a data property that is an array of instances returned by hydrateInstance and should return the right type of list.
Parameters
- listInstanceData
{Object}:An object that contains an array of instances.
- set
{Set}:The set this list belongs to.
Use
If you have a special type of list with helper functions you'd like to have available,
you can do that in list. The following makes it so getList resolves to array-like
objects that have a completed function.
var MyList = Object.create(Array.prototype);
MyList.prototype.completed = function(){
return this.filter(function(){ return this.completed });
};
var todosConnection = connect([
require("can-connect/constructor/constructor"),
require("can-connect/data/url/url")
], {
url: "todos",
list: function(listData, set){
var collection = Object.create(MyList);
Array.apply(collection, listData.data);
collection.__listSet = set;
return collection;
}
});
This allows:
todosConnection.getList({}).then(function(todos){
console.log("There are",todos.completed().length, "completed todos")
});
Notice that we added the default listSetProp (__listSet) data on the list. This is useful
for other extensions.