destroy
function
Destroys an instance using the underlying data interface.
connection.destroy( instance )
To destroy an instance, its serialized data is passed to
destroyData. If destroyData's promise resolves to anything other than undefined,
destroyedInstance is called.
Parameters
- instance
{Instance}:The instance to create or save.
Use
To use destroy, create a connection, then retrieve an instance, and call .destroy() with it.
// Create a connection:
var todoConnection = connect([
require('can-connect/constructor/constructor'),
require('can-connect/data/url/url')
],{
url: "/todos"
})
// Get a todo instance
todoConnection.get({id: 5}).then(function(todo){
// Call .destroy():
todoConnection.destroy(todo)
});
This will DELETE to /todos/5 with the todo data. The server response data
might look something like:
{}
This data will be passed to destroyedInstance.