Skip to content

Commit

Permalink
release for version 0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sasaplus1 committed Jun 13, 2016
2 parents c3734d9 + ee8a7d6 commit 81c2463
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.6.3 / 2016-06-13

- fixed #10, #11, #12

# 0.6.2 / 2016-06-12

- fixed #10
Expand Down
8 changes: 5 additions & 3 deletions build/deepcopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ return /******/ (function(modules) { // webpackBootstrap
var resultValue = copyValue(target);

if (resultValue !== null) {
return copyValue(target);
return resultValue;
}

return copyCollection(target, customizer);
Expand Down Expand Up @@ -361,15 +361,17 @@ return /******/ (function(modules) { // webpackBootstrap
value = target[key];
index = (0, _polyfill.indexOf)(visited, value);

resultCopy = void 0;
result = void 0;
ref = void 0;

if (index === -1) {
resultCopy = (0, _copy.copy)(value, customizer);
result = resultCopy !== null ? resultCopy : value;

if (value !== null && /^(?:function|object)$/.test(typeof value)) {
visited.push(value);
reference.push(result);
} else {
ref = result;
}
} else {
// circular reference
Expand Down
2 changes: 1 addition & 1 deletion build/deepcopy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deepcopy",
"version": "0.6.2",
"version": "0.6.3",
"author": "sasa+1 <sasaplus1@gmail.com>",
"contributors": [
"kjirou <kjirou.web@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion src/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function copy(target, customizer) {
const resultValue = copyValue(target);

if (resultValue !== null) {
return copyValue(target);
return resultValue;
}

return copyCollection(target, customizer);
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ function recursiveCopy(target, customizer, clone, visited, reference) {
value = target[key];
index = indexOf(visited, value);

resultCopy = undefined;
result = undefined;
ref = undefined;

if (index === -1) {
resultCopy = copy(value, customizer);
result = (resultCopy !== null) ? resultCopy : value;

if (value !== null && /^(?:function|object)$/.test(typeof value)) {
visited.push(value);
reference.push(result);
} else {
ref = result;
}
} else {
// circular reference
Expand Down
52 changes: 52 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,58 @@ describe('deepcopy', function() {
assert(functionInArrayInArray.a[1][1] === copiedFunctionInArrayInArray.a[1][1]);
});

it('can copy deeper Object and Array', function() {
const array = [
1,
2,
[
3,
4,
[
function() {},
6,
7
]
]
];

const copiedArray = deepcopy(array);

assert(array !== copiedArray);
assert(array[0] === copiedArray[0]);
assert(array[1] === copiedArray[1]);
assert(array[2] !== copiedArray[2]);
assert(array[2][0] === copiedArray[2][0]);
assert(array[2][1] === copiedArray[2][1]);
assert(array[2][2] !== copiedArray[2][2]);
assert(array[2][2][0] !== copiedArray[2][2][0]);
assert(array[2][2][1] === copiedArray[2][2][1]);
assert(array[2][2][2] === copiedArray[2][2][2]);

const object = {
a: 'a',
b: 'b',
c: {
d: function() {},
e: {
f: 'f',
g: 'g'
}
}
};

const copiedObject = deepcopy(object);

assert(object !== copiedObject);
assert(object.a === copiedObject.a);
assert(object.b === copiedObject.b);
assert(object.c !== copiedObject.c);
assert(object.c.d !== copiedObject.c.d);
assert(object.c.e !== copiedObject.c.e);
assert(object.c.e.f === copiedObject.c.e.f);
assert(object.c.e.g === copiedObject.c.e.g);
});

it('can copy Class from Array and Object by customizer', function() {
function MyClass(number) {
this.number = +number;
Expand Down

0 comments on commit 81c2463

Please sign in to comment.