can-define
Advanced tools
Comparing version 2.3.3 to 2.3.4
@@ -781,2 +781,19 @@ "use strict"; | ||
}); | ||
// normalize Type that implements can.new | ||
if(def.Type) { | ||
var value = def.Type; | ||
var serialize = value[serializeSymbol]; | ||
if(serialize) { | ||
definition.serialize = function(val){ | ||
return serialize.call(val); | ||
}; | ||
} | ||
if(value[newSymbol]) { | ||
definition.type = value[newSymbol]; | ||
delete definition.Type; | ||
} | ||
} | ||
// We only want to add a defaultDefinition if def.type is not a string | ||
@@ -811,12 +828,3 @@ // if def.type is a string it is handled in addDefinition | ||
else if(value && (value[serializeSymbol] || value[newSymbol]) ) { | ||
definition = {}; | ||
var serialize = value[serializeSymbol]; | ||
if(serialize) { | ||
definition.serialize = function(val){ | ||
return serialize.call(val); | ||
}; | ||
} | ||
if(value[newSymbol]) { | ||
definition.type = value[newSymbol]; | ||
} | ||
definition = { Type: value }; | ||
} | ||
@@ -823,0 +831,0 @@ else if(typeof value === "function") { |
@@ -1331,1 +1331,47 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
QUnit.test("primitive types work with val: Type", function(){ | ||
var UpperCase = {}; | ||
UpperCase[canSymbol.for("can.new")] = function(val){ | ||
return val.toUpperCase(); | ||
}; | ||
var Type = DefineMap.extend({ | ||
val: UpperCase | ||
}); | ||
var type = new Type({ val: "works" }); | ||
QUnit.equal(type.val, "WORKS", "it worked"); | ||
}); | ||
QUnit.test("primitive types work with val: {Type: Type}", function(){ | ||
var UpperCase = {}; | ||
UpperCase[canSymbol.for("can.new")] = function(val){ | ||
return val.toUpperCase(); | ||
}; | ||
var Type = DefineMap.extend({ | ||
val: { | ||
Type: UpperCase | ||
} | ||
}); | ||
var type = new Type({ val: "works" }); | ||
QUnit.equal(type.val, "WORKS", "it worked"); | ||
}); | ||
QUnit.test("primitive types work with val: {type: Type}", function(){ | ||
var UpperCase = {}; | ||
UpperCase[canSymbol.for("can.new")] = function(val){ | ||
return val.toUpperCase(); | ||
}; | ||
var Type = DefineMap.extend({ | ||
val: { | ||
type: UpperCase | ||
} | ||
}); | ||
var type = new Type({ val: "works" }); | ||
QUnit.equal(type.val, "WORKS", "it worked"); | ||
}); |
{ | ||
"name": "can-define", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Create observable objects with JS dot operator compatibility", | ||
@@ -5,0 +5,0 @@ "main": "can-define.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
304613
7268