addListReference
Adds a reference to a list so it can be easily looked up.
connection.addListReference( list[, set] )
Adds a reference to a list in the listStore. The number of references are incremented.
Use
The listStore contains a collection of lists
created for each listSet. The listStore is used to prevent creating the
same list multiple times and for identifying a list for a given set. Lists need to be added to this store for this behavior
to happen. To do this, call addListReference like the following:
// A basic connection:
var todoConnection = connect([
require("can-connect/constructor/store/store"),
require("can-connect/constructor/constructor"),
require("can-connect/data/url/url")
], {
url: "/todos"
});
var dueToday;
// Get a todo:
todoConnection.getList({due: "today"}).then(function( todos ){
// Add it to the store
todoConnection.addListReference(todos, {due: "today"});
dueToday = todos;
});
Now, if you were to retrieve the same data sometime later, it would be the same list.
todoConnection.get({due: "today"}).then(function( todos ){
todos === dueToday //-> true
});
The .getListData response data is passed with dueToday to updatedList
which can update dueToday with the new data.
All these lists stay in memory. Use deleteListReference to remove them.
Typically, addListReference is called when something expresses interest in the list, such
as an event binding, and deleteListReference is called when interest is removed.