Skip to content

can-connect/can/merge/merge

Compare
Choose a tag to compare
@justinbmeyer justinbmeyer released this 10 Jan 15:26
· 457 commits to master since this release

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:

  1. Related types have an .algebra property that is configured with id.
Student = DefineMap.extend({ ... });

Student.algebra = new set.Algebra(set.props.id("_id"))
  1. 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"
});
  1. Lists of related types use # to point to that type:
Student.List = DefineList.extend({
    "#": Student
});
  1. 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
});