Comments (7)
Ok got it, will think about this.
It's not clear what to do if childrenPath is deep. not just next level property.
like here
if this option is true - then we need to remove only property by the last key of children's path, not the whole path.
from deepdash.
Also check what's wrong with Lodash cloneDeep, as found by @GaborTorma in #56
It keeps deep function values instead of turning them into empty objects as per docs.
from deepdash.
Opened yet another issue about this in Lodash
from deepdash.
Currently, we have these issues with filterDeep:
it pretends to return a filtered clone of a given object, but the quality of this clone is far from one provided by Lodash's clone/cloneDeep.
filterDeep assumes the data consists of objects, arrays, and primitives.
we need to carefully handle such cases as
- class instances
- typed arrays
- maps and sets
- buffers and data views
- regexes
- functions
- read-only getters
- etc..
all this great job already is done in Lodash, so the first step will be to properly use clone/cloneDeep. - we need let Lodash clone regexes, maps, etc
- to avoid deep cloning of data under the childrenPath
- I have a LOT to learn from Lodash clone method.
For example here is a small test how cone works:
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
from deepdash.
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)
from deepdash.
you probably posted a wrong link - your example is just template without filtering done.
But the option you are asking about is already there - read about "keepIfEmpty" ones
https://deepdash.io/#filterdeep
from deepdash.
Wow... I forgot to fork it, sorry. Yes, but only if I do not use childrenPath
: https://codepen.io/muuvmuuv/pen/VweJLPe?editors=0011
from deepdash.
Related Issues (20)
- omitDeep changes input on empty array HOT 1
- omitDeep doesn't omit objects HOT 7
- ERR_PACKAGE_PATH_NOT_EXPORTED HOT 3
- how to remove values from json if they exist
- Feature Request Parent path
- filterDeep not working on deeply nested object HOT 2
- Working with promises HOT 2
- Frustrating that things like `pickDeep` and `filterDeep` can only return a nested structure HOT 3
- deepdash-es not working with jest-resolve HOT 9
- deepFilter keep parents
- ESM: IIterateeContext typescript interface not exposed
- findPathDeep doesn't return first Value path
- findDeep or findDeepValue - Return object that contains the key & value
- eachDeep with childrenPath == wrong parent, parent path etc
- Bug in documentation _.findDeep*
- findDeep return types problem HOT 3
- Add contributing docs HOT 1
- findDeep is not a function HOT 1
- explicit return values, why and how does this work HOT 1
- mapValuesDeep mutates the original object if `leavesOnly: false` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepdash.