Skip to content

Commit

Permalink
rebuild: add Set and Map support to Oblect.clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed Jul 25, 2018
1 parent 678f9d7 commit 04e36b5
Show file tree
Hide file tree
Showing 7 changed files with 7,146 additions and 3,984 deletions.
32 changes: 27 additions & 5 deletions dist/super.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var PrimitiveType = {
var InstanceType = {
OBJECT: Object,
ARRAY: Array,
SET: Set,
MAP: Map,
REGEXP: RegExp,
DATE: Date
};
Expand Down Expand Up @@ -3085,25 +3087,45 @@ var _Object = function (_extendableBuiltin2) {
return copy;
}

if (item instanceof InstanceType.SET) {
var _copy = new Set();

item.forEach(function (v) {
return _copy.add(_clone(v));
});

return _copy;
}

if (item instanceof InstanceType.MAP) {
var _copy2 = new Map();

item.forEach(function (v, k) {
return _copy2.set(k, _clone(v));
});

return _copy2;
}

if (item instanceof InstanceType.OBJECT) {
var _copy = {};
var _copy3 = {};

// $FlowFixMe
Object.getOwnPropertySymbols(item).forEach(function (s) {
return _copy[s] = _clone(item[s]);
return _copy3[s] = _clone(item[s]);
});

if (includeNonEnumerable) {
Object.getOwnPropertyNames(item).forEach(function (k) {
return _copy[k] = _clone(item[k]);
return _copy3[k] = _clone(item[k]);
});
} else {
Object.keys(item).forEach(function (k) {
return _copy[k] = _clone(item[k]);
return _copy3[k] = _clone(item[k]);
});
}

return _copy;
return _copy3;
}

throw new Error("Unable to copy object: " + item);
Expand Down
32 changes: 27 additions & 5 deletions dist/super.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
var InstanceType = {
OBJECT: Object,
ARRAY: Array,
SET: Set,
MAP: Map,
REGEXP: RegExp,
DATE: Date
};
Expand Down Expand Up @@ -3091,25 +3093,45 @@
return copy;
}

if (item instanceof InstanceType.SET) {
var _copy = new Set();

item.forEach(function (v) {
return _copy.add(_clone(v));
});

return _copy;
}

if (item instanceof InstanceType.MAP) {
var _copy2 = new Map();

item.forEach(function (v, k) {
return _copy2.set(k, _clone(v));
});

return _copy2;
}

if (item instanceof InstanceType.OBJECT) {
var _copy = {};
var _copy3 = {};

// $FlowFixMe
Object.getOwnPropertySymbols(item).forEach(function (s) {
return _copy[s] = _clone(item[s]);
return _copy3[s] = _clone(item[s]);
});

if (includeNonEnumerable) {
Object.getOwnPropertyNames(item).forEach(function (k) {
return _copy[k] = _clone(item[k]);
return _copy3[k] = _clone(item[k]);
});
} else {
Object.keys(item).forEach(function (k) {
return _copy[k] = _clone(item[k]);
return _copy3[k] = _clone(item[k]);
});
}

return _copy;
return _copy3;
}

throw new Error("Unable to copy object: " + item);
Expand Down
12 changes: 6 additions & 6 deletions dist/super.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 04e36b5

Please sign in to comment.