Replies: 7 comments
-
Also check what's wrong with Lodash cloneDeep, as found by @GaborTorma in #56 |
Beta Was this translation helpful? Give feedback.
-
Opened yet another issue about this in Lodash |
Beta Was this translation helpful? Give feedback.
-
Currently, we have these issues with filterDeep:
console.clear();
class Test {
constructor(x) {
console.log('constructor',x); // called once
if(!x)throw 'XXX!!!'; // no error, clone doesn't call it
this.a = "a";
this.b = "b";
this.c = "c";
this.x = x;
}
test(){
console.log('test');
}
get z(){
return 'z';
}
}
const t = new Test('x');
t.d='d';
delete t.b;
t.hi = ()=>{console.log('hi')};
const tt = _.cloneDeep(t);
console.log(t); // Test {a: "a", c: "c", x: "x", d: "d"}
console.log(tt); // Test {a: "a", c: "c", x: "x", d: "d"}
t.test(); // works
tt.test(); // works
tt.hi(); // works, but I bieleve it's a Lodash's bug, according to docs tt.hi should by {} after cloning
console.log(t.test===tt.test); // equal because of this method comes from prototype
console.log(t.hi===tt.hi); // equal, but I bieleve it's a Lodash's bug, according to docs tt.hi should by {} after cloning
console.log(tt.z); // getters are functions in prototype, so it works |
Beta Was this translation helpful? Give feedback.
-
I would also like to add a new option to exclude the children from the output when it is empty. Example: https://codepen.io/yurigor/pen/GaKvNm?editors=0010 (parent 1.2 should not have children because it is empty) |
Beta Was this translation helpful? Give feedback.
-
you probably posted a wrong link - your example is just template without filtering done. |
Beta Was this translation helpful? Give feedback.
-
Wow... I forgot to fork it, sorry. Yes, but only if I do not use |
Beta Was this translation helpful? Give feedback.
-
Ok got it, will think about this. |
Beta Was this translation helpful? Give feedback.
-
Same like in
filterDeep
we havecloneDeep
option to let the user specify his own cloning method,we need also to review all the deepdash methods where flat
_.clone
method used and also let user replace it.Beta Was this translation helpful? Give feedback.
All reactions