createData
Creates a new record in the connection.
function(instanceData, cid)
Creates a new record given the serialized form of the data. Resolves to a promise with any additional properties that should be added to the instance. A client ID is passed of the instance that is being created.
The following shows how constructor calls createData
and what it does with the response:
var CID = require("can-util/js/cid/cid");
// Create an instance of a special type
var myInstance = new MyType({ ... });
// get its CID
var cid = CID(myInstance);
// get its raw data
var instanceData = connection.serializeInstance(myInstance);
connection.createData(instanceData, cid).then(function(createdInstanceData){
connection.createdInstance(myInstance, createdInstanceData);
})
Parameters
- instanceData
{Object}
:The serialized data of the instance.
- cid
{Number}
:A unique id that represents the instance that is being created. Given this value, the instance can be retrieved in the cidStore.
Returns
{Promise<Object>}
:
A promise resolved with the created data of the newly created instance. The created data must have the id of the created record.
By default, createdInstance only adds the data in createdInstanceData
to
myInstance
, it does not remove it. To remove "missing" properties on myInstance
that are not in createdInstanceData
, overwrite
createdInstance.