can-connect/can/constructor-hydrate/
The can-connect/can/constructor-hydrate/constructor-hydrate
behavior allows to check the connection instanceStore when creating new instances of the connected Map type.
It should be used with can-connect/constructor/store and can-connect/can/map/map behaviors:
var Student = DefineMap.extend({});
Student.List = DefineList.extend({
'#': { Type: Student }
});
Student.connection = connect([
require("can-connect/data/url/url"),
require("can-connect/constructor/constructor"),
require("can-connect/constructor/store/store"),
require("can-connect/can/map/map"),
require("can-connect/can/constructor-hydrate/constructor-hydrate"),
], {
Map: Student,
List: Student.List,
url: "api/students"
});
Now if we try to create two instances with the same id they both will be the same instance:
Student.get({id: 1}).then(function(instance){
var student = instance;
var teamLead = new Student({id: 1});
student === teamLead;
});