Code Monkey home page Code Monkey logo

Comments (7)

YuriGor avatar YuriGor commented on May 29, 2024 1

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.

YuriGor avatar YuriGor commented on May 29, 2024

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.

YuriGor avatar YuriGor commented on May 29, 2024

Opened yet another issue about this in Lodash

from deepdash.

YuriGor avatar YuriGor commented on May 29, 2024

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.

muuvmuuv avatar muuvmuuv commented on May 29, 2024

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.

YuriGor avatar YuriGor commented on May 29, 2024

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.

muuvmuuv avatar muuvmuuv commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.