mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
Cleanup, more coverage
This commit is contained in:
1 parent
d2f122936e
commit
e6da33582c
4 files changed
+6
-47
No files matched your search
@@ -1,48 +1,7 @@
|
||||
var copyChildren = function(d){
|
||||
var copied = clone(d);
|
||||
copy = [];
|
||||
if(copied.children){
|
||||
copied.children.forEach(function(h){
|
||||
copy.push(h);
|
||||
});
|
||||
}
|
||||
if(copied._children){
|
||||
copied._children.forEach(function(h){
|
||||
copy.push(h);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var clone = function(obj) {
|
||||
if (null == obj || "object" != typeof obj) return obj;
|
||||
var copy = obj.constructor();
|
||||
for (var attr in obj) {
|
||||
if (obj.hasOwnProperty(attr) && attr != "parent"){
|
||||
if(attr == "children" && obj[attr] != null){
|
||||
copy[attr] = obj[attr].map(function (d) {
|
||||
var subCopy = clone(d);
|
||||
return subCopy;
|
||||
});
|
||||
}
|
||||
else if(attr == "_children" && obj[attr] != null){
|
||||
copy[attr] = obj[attr].map(function(d) {
|
||||
var subCopy = clone(d);
|
||||
return subCopy;
|
||||
});
|
||||
}
|
||||
else{
|
||||
copy[attr] = obj[attr];
|
||||
}
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
var deepclone = function(obj){
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clone:clone,
|
||||
deepclone:deepclone,
|
||||
};
|
||||
Reference in new issue
Block a user