instance
property
Returns the typed form of the raw data.
connection.instance( props )
Takes raw data and runs it through hydrateInstance.
Parameters
- props
{Object}:
Use
If you have a special type with helper functions you'd like to have available,
you can convert raw data to that type in instance. The following makes it so
.get resolves to objects with a complete method.
Todo = function(props){
Object.assign(this, props);
};
Todo.prototype.complete = function(){
this.completed = true;
}
var todosConnection = connect([
require("can-connect/constructor/constructor"),
require("can-connect/data/url/url")
], {
url: "todos",
instance: function( props ) {
return new Todo(props);
}
});
This allows:
todosConnection.get({id: 5}).then(function(todo){
todo.complete();
});