destroy
Delete an instance from the connection data source
connection.destroy( instance )
To destroy an instance, it's serialized data is passed
to destroyData. If destroyData's promise resolves to anything
other than undefined
, destroyedInstance is called.
Parameters
- instance
{Instance}
:the instance being deleted from the data source
Use
To use destroy
, create a connection, retrieve an instance, and then call .destroy()
with it.
// create a connection
var constructor = require('can-connect/constructor/');
var dataUrl = require('can-connect/data/url/');
var todoConnection = connect([dataUrl, constructor], {
url: "/todos"
})
// retrieve a todo instance
todoConnection.get({id: 5}).then(function(todo){
// Call .destroy():
todoConnection.destroy(todo)
});
.destroy()
above will call destroyData
on the data/url
behavior, which will make an HTTP DELETE request to /todos/5
with the serialized todo
data. The server
response data may look something like:
{
deleted: true
}
That response data will be passed to destroyedInstance, which by default
adds those properties to todo
.