Skip to content

Commit cb594d8

Browse files
authored
Merge pull request #481 from canjs/new
Use can.new symbol to create new List types
2 parents e5f8510 + 62d2bc1 commit cb594d8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Diff for: can/map/map.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ var canMapBehavior = behavior("can/map",function(baseConnection){
336336
*/
337337
list: function(listData, set){
338338
var _List = this.List || (this.Map && this.Map.List);
339-
var list = new _List(listData.data);
339+
var list = canReflect.new(_List, listData.data);
340340
canReflect.eachKey(listData, function (val, prop) {
341341
if (prop !== 'data') {
342342
canReflect.setKeyValue(list, prop, val);

Diff for: can/map/map_test.js

+29
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var $ = require("jquery");
33
var Map = require("can-map");
44
var List = require("can-list");
55
var Observation = require("can-observation");
6+
var canSymbol = require("can-symbol");
67
var canReflect = require("can-reflect");
78

89
// load connections
@@ -538,3 +539,31 @@ QUnit.test("should batch model events", function(assert) {
538539

539540
assert.equal(eventOrder.join(""), "1234", "events are batched");
540541
});
542+
543+
QUnit.test("list uses can.new", function(assert) {
544+
var Todo = function(props) {};
545+
var TodoList = function() {
546+
var array = Array.apply(this, arguments);
547+
return array;
548+
};
549+
TodoList[canSymbol.for("can.new")] = function(items) {
550+
var list = new TodoList();
551+
return TodoList.apply(list, items);
552+
};
553+
554+
var todoConnection = connect([
555+
constructor,
556+
canMap],
557+
{
558+
url: "/services/todos",
559+
Map: Todo,
560+
List: TodoList
561+
});
562+
563+
var list = todoConnection.list({
564+
data: [{id:1, label: "walk the dog"},
565+
{id:2, label: "make dinner"}]
566+
});
567+
568+
assert.equal(list.length, 2, "Has all of the items");
569+
});

0 commit comments

Comments
 (0)