DataInterface
The most common raw data methods.
DataInterface
The DataInterface
methods are the methods most used most commonly
by can-connect
behaviors to get or mutate information in some form of
persisted storage. The DataInterface
methods only operate on raw
data comprised of plain JavaScript Objects, Arrays and primitive types.
This is in contrast to the InstanceInterface methods that
operate on typed data.
Those methods are:
- clear - Remove all records.
- createData - Create a new record.
- destroyData - Destroy a record.
- getData - Get a single record.
- getListData - Get multiple records.
- getSets - Get the Sets available within the persisted storage.
- updateData - Update a single record.
- updateListData - Update multiple records.
Behaviors either implement these methods or overwrite these methods to perform some extra functionality.
For example, data/url implements these behaviors to make an Ajax request like:
connect.behavior("data/url", function(baseConnection) {
return {
getListData: function(set){
return ajax({
type: "GET",
url: this.url,
data: set
});
},
getData: function(){ ... },
...
}
});
The can-connect/data/parse/parse behavior overwrites the baseConnection
’s methods to
perform cleanup on the response data:
connect.behavior("data/parse", function(baseConnection) {
return {
getListData: function(set){
var self = this;
return baseConnection.getListData(set).then(function(response){
return self.parseListData(response);
});
},
getData: function(){ ... },
...
}
});