data/callbacks
Extend DataInterface methods to call callbacks with the raw response data.
dataCallbacks( baseConnection )
Extends the DataInterface create, update, read & delete methods to call 'callback' methods following their execution. Callbacks are called with the data returned from the underlying behavior's DataInterface implementation.
For example:
var dataUrl = require("can-connect/data/url/");
var dataCallbacks = require("can-connect/data/url");
var logging = {
createdData: function(responseData) {
console.log('New Todo Saved: ', responseData);
return responseData;
}
};
var todoConnection = connect([dataUrl, dataCallbacks, logging}], {
url: '/todos'
});
// create a new todo
todoConnection.createData({name: "do the dishes", completed: false}).then(function(responseData) {
responseData; // {id: 5}
});
// after create request is completed, following is logged by the "logging" createdData callback:
// > New Todo Saved: {id: 5}
Parameters
- baseConnection
{Object}
:can-connect
connection object that is having thedata/callbacks
behavior added on to it. Should already contain a behavior that provides the DataInterface (e.g data/url). If theconnect
helper is used to build the connection, the behaviors will automatically be ordered as required.
Returns
{Object}
:
a can-connect
connection containing the method implementations provided by data/callbacks
.