can-reflect
Advanced tools
Comparing version 1.14.2 to 1.14.3
{ | ||
"name": "can-reflect", | ||
"version": "1.14.2", | ||
"version": "1.14.3", | ||
"description": "reflection on unknown data types", | ||
@@ -5,0 +5,0 @@ "homepage": "http://canjs.com", |
@@ -307,11 +307,12 @@ var QUnit = require('steal-qunit'); | ||
var arr = []; | ||
QUnit.ok(shapeReflections.isSerializable(arr)); | ||
QUnit.ok(!shapeReflections.isSerialized(arr), "array is not isSerialized"); | ||
QUnit.ok(!shapeReflections.isSerialized({}), "obj is not isSerialized"); | ||
arr[canSymbol.for('can.setKeyValue')] = function() {}; | ||
QUnit.ok(!shapeReflections.isSerializable(arr)); | ||
QUnit.ok(!shapeReflections.isSerialized(arr)); | ||
if (testHelpers.setSupported) { | ||
var set = new Set([{}, {}, {}]); | ||
QUnit.ok(shapeReflections.isSerializable(set)); | ||
QUnit.ok(shapeReflections.isSerialized(set)); | ||
set[canSymbol.for("can.setKeyValue")] = function() {}; | ||
QUnit.ok(!shapeReflections.isSerializable(set)); | ||
QUnit.ok(!shapeReflections.isSerialized(set)); | ||
} | ||
@@ -554,2 +555,12 @@ }); | ||
QUnit.test("serialize clones arrays", function(){ | ||
var obj = {foo: [{zed: "ted"}]}; | ||
var obj2 = shapeReflections.serialize(obj); | ||
QUnit.deepEqual(obj2, obj, "deep equal"); | ||
QUnit.notOk(obj === obj2, "ret not the same"); | ||
QUnit.notOk(obj.foo === obj2.foo, "foo not the same"); | ||
QUnit.notOk(obj.foo[0] === obj2.foo[0]); | ||
}); | ||
/*QUnit.test("getAllEnumerableKeys", function(){ | ||
@@ -556,0 +567,0 @@ |
@@ -80,3 +80,4 @@ var canSymbol = require("can-symbol"); | ||
function isSerializable(obj){ | ||
// is the value itself its serialized value | ||
function isSerializedHelper(obj){ | ||
if (typeReflections.isPrimitive(obj)) { | ||
@@ -88,3 +89,3 @@ return true; | ||
} | ||
return typeReflections.isBuiltIn(obj) && !typeReflections.isPlainObject(obj); | ||
return typeReflections.isBuiltIn(obj) && !typeReflections.isPlainObject(obj) && !Array.isArray(obj); | ||
} | ||
@@ -110,3 +111,3 @@ | ||
return function serializer(value, MapType){ | ||
if (isSerializable(value)) { | ||
if (isSerializedHelper(value)) { | ||
return value; | ||
@@ -654,3 +655,3 @@ } | ||
* ``` | ||
* | ||
* | ||
* @param {Object} obj A map-like or array-like object. | ||
@@ -1039,3 +1040,3 @@ * @return {Object} Returns objects and arrays. | ||
}, | ||
isSerializable: isSerializable, | ||
isSerialized: isSerializedHelper, | ||
/** | ||
@@ -1137,3 +1138,5 @@ * @function can-reflect.size size | ||
}; | ||
shapeReflections.isSerializable = shapeReflections.isSerialized; | ||
shapeReflections.keys = shapeReflections.getOwnEnumerableKeys; | ||
module.exports = shapeReflections; |
165469
4512