Skip to content

Commit

Permalink
Merge pull request #426 from canjs/fix-wildcard-type-def-constructors
Browse files Browse the repository at this point in the history
Wildcard constructor types should work
  • Loading branch information
cherifGsoul authored Feb 1, 2019
2 parents 9e8d860 + 3d84f25 commit 3faa46d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions can-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,8 @@ define.expando = function(map, prop, value) {
// possibly convert value to List or DefineMap
if(defaultDefinition.type) {
map._data[prop] = define.make.set.type(prop, defaultDefinition.type, returnFirstArg).call(map, value);
} else if (defaultDefinition.Type && canReflect.isConstructorLike(defaultDefinition.Type)) {
map._data[prop] = define.make.set.Type(prop, defaultDefinition.Type, returnFirstArg).call(map, value);
} else {
map._data[prop] = define.types.observable(value);
}
Expand Down
27 changes: 27 additions & 0 deletions map/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,30 @@ QUnit.test("Set __inSetup prop #421", function() {
map.set("__inSetup", "nope");
QUnit.equal(map.__inSetup, "nope");
});

QUnit.test("'*' wildcard type definitions that use constructors works for expandos #425", function(){
var MyType = function MyType() {};
MyType.prototype = {};

var OtherType = DefineMap.extend({ seal : false }, {
"*" : MyType
});

var map = new OtherType();
map.set( "foo", {});
var foo = map.get( "foo" );
QUnit.ok(foo instanceof MyType);
});

QUnit.test("'*' wildcard type definitions that use DefineMap constructors works for expandos #425", function(){
var MyType = DefineMap.extend({});

var OtherType = DefineMap.extend({ seal : false }, {
"*" : MyType
});

var map = new OtherType();
map.set( "foo", {});
var foo = map.get( "foo" );
QUnit.ok(foo instanceof MyType);
});

0 comments on commit 3faa46d

Please sign in to comment.