Comparing version
@@ -44,13 +44,2 @@ (function (global, factory) { | ||
function deepMerge(a, b) { | ||
props(b).forEach(function (k) { | ||
if (typeof a[k] === 'object' && typeof b[k] === 'object') { | ||
a[k] = a[k].deepMerge(b[k]); | ||
} | ||
else { | ||
a[k] = b[k]; | ||
} | ||
}); | ||
} | ||
function thaw(source, constructor) { | ||
@@ -85,3 +74,15 @@ return merge(new (constructor || source.constructor), source); | ||
FrozenObject.prototype.deepMerge = updater(function (obj) { | ||
deepMerge(this, obj); | ||
var a = this; | ||
var b = obj; | ||
props(b).forEach(function (k) { | ||
if (typeof a[k] === 'object' && | ||
typeof b[k] === 'object' && | ||
!Array.isArray(b[k]) && | ||
!(a[k] instanceof FrozenArray)) { | ||
a[k] = a[k].deepMerge(b[k]); | ||
} | ||
else { | ||
a[k] = b[k]; | ||
} | ||
}); | ||
}); | ||
@@ -88,0 +89,0 @@ |
{ | ||
"name": "copykitten", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Tiny immutable JSON data structures", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -175,3 +175,6 @@ var assert = (typeof chai === 'undefined') ? | ||
} | ||
} | ||
}, | ||
tags: [{id: 1, name: 'one'}, 2, 3, 4], | ||
foo: {a: 1}, | ||
bar: ['bar'] | ||
}); | ||
@@ -188,3 +191,6 @@ var obj2 = obj.deepMerge({ | ||
something: 'else' | ||
} | ||
}, | ||
tags: [{id: 1}], | ||
foo: ['foo'], | ||
bar: {b: 2} | ||
}); | ||
@@ -203,3 +209,6 @@ assert.deepEqual(JSON.parse(JSON.stringify(obj2)), { | ||
something: 'else' | ||
} | ||
}, | ||
tags: [{id: 1}], | ||
foo: ['foo'], | ||
bar: {b: 2} | ||
}); | ||
@@ -206,0 +215,0 @@ }); |
399723
0.09%11213
0.1%