Releases: canjs/can-connect
Bugfix: constructor/callbacks-once/
The callback-once
behavior is to prevent calling the same callbacks multiple times for the same data. E.g. if a new item is created via AJAX, but also WebSocket might receive a "created" event.
The bug was that the behavior didn't consider the method names, e.g. if createdInstance
was called for an item then destroyedInstance
was not called for the same item.
Maximum call stack if two instances without id are created (can/constructor-hydrate)
can/ref/ref
Set value
if its passed for an already existing item in Ref.store
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;
});
can-connect/can/merge/merge
This adds the can-connect/can/merge/merge
behavior from #238. Use it to merge can-define
with minimal changes and awareness of other connections.
To use make sure your types are configured as follows:
- Related types have an
.algebra
property that is configured withid
.
Student = DefineMap.extend({ ... });
Student.algebra = new set.Algebra(set.props.id("_id"))
- Related types that have a connection are configured with a
.connection
property that points to that connection.
Student.connection = baseMap({
Map: Student,
List: Student.List,
url: "/services/students",
name: "students"
});
- Lists of related types use
#
to point to that type:
Student.List = DefineList.extend({
"#": Student
});
- The base type is configured similar to above, and its connection has
canMergeBehavior
mixed in as follows:
var canMergeBehavior = require("can-connect/can/merge/merge");
var canMapBehavior = require("can-connect/can/map/map");
var ClassRoom = DefineMap.extend({
students: Student.List
});
ClassRoom.List = DefineList.extend({
"#": ClassRoom
});
ClassRoom.algebra = new set.Algebra({...})
ClassRoom.connection = connect([..., canMapBehavior, canMergeBehavior, ...],{
Map: ClassRoom,
List: ClassRoom.List
});
Smart Merge
Adds the smart merge helper so it's easier to work with nested structures.
Fix real-time behavior's destroyInstance method
When data passes through the destroyInstance
method in the real-time
behavior, "destroyed"
events will now properly get triggered.
PR: #227
createInstance triggers Map "created" event
Calling createInstance
will now trigger the created
event on any connected Map
constructor.
var Session = DefineMap.extend({
id: 'any',
email: 'string'
});
var connection = connect([
constructor,
canMap,
constructorStore,
dataCallbacks,
realTime,
callbacksOnce
], {
Map: Session
});
Session.on('created', function (event) {
assert.ok(event, 'createInstance triggered the "created" event');
done();
});
connection.createInstance({
id: 5,
email: '[email protected]'
});
PR: #225
Stop using deprecated can-util methods
#213 - Stop using deprecated can-util methods.