Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jfet97 committed Jan 6, 2019
1 parent aaf73a8 commit b88741f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/main.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": "omniclone",
"version": "0.3.3",
"version": "0.3.4",
"description": "deep cloning function for js objects",
"main": "dist/main.js",
"scripts": {
Expand Down
20 changes: 16 additions & 4 deletions src/deepclone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function deepClone(source, config) {
// A reference to the initial source object
const start = source;

function propsHandler(res, descriptors, config) {
function propsHandler(res, descriptors, config, references) {
// sibiling safe references
// if an object contains another object more than one times
// storing its reference in more than one prop
Expand All @@ -18,7 +18,13 @@ function deepClone(source, config) {
// if circular references are not supported

// it will be called just after the definition
function innerPropsHandler(res, descriptors, safeReferences, config) {
function innerPropsHandler(
res,
descriptors,
config,
safeReferences,
references
) {
const {
copyNonEnumerables,
copySymbols,
Expand Down Expand Up @@ -154,7 +160,13 @@ function deepClone(source, config) {
}
});
}
return innerPropsHandler(res, descriptors, safeReferences, config);
return innerPropsHandler(
res,
descriptors,
config,
safeReferences,
references
);
}

function updateReferences(res, references) {
Expand Down Expand Up @@ -229,7 +241,7 @@ function deepClone(source, config) {
}

// deep copy each prop from the source object to the res object and put them into the res object
propsHandler(res, ownPropsDcps, config);
propsHandler(res, ownPropsDcps, config, references);

// circular references update from temp old values to new ones
if (allowCircularReferences) {
Expand Down

0 comments on commit b88741f

Please sign in to comment.