YuriGor / deepdash

eachDeep, filterDeep, findDeep, someDeep, omitDeep, pickDeep, keysDeep etc.. Tree traversal library written in Underscore/Lodash fashion
https://deepdash.io/
MIT License
272 stars 12 forks source link

eachDeep with childrenPath == wrong parent, parent path etc #143

Open alexNecroJack opened 1 year ago

alexNecroJack commented 1 year ago

I will start by saying, THANK YOU(!) for this great library (the Deepdash part of Loadash).

I have a simple structure,

window.inheritanceTree = {
    "variable": {
        "0": "string",
        "number": {
            "0": "int",
            "1": "float",
            "2": "double",
            "decimal": [
                "float",
                "double"
            ]
        }
    },
    "0": "template",
    "1": "view",
    "2": "data"
};

And then I make a simple call: _.eachDeep(window.inheritanceTree, function(){console.log(arguments)}, {childrenPath: ['variable.number.decimal']});

The expected output for "float" for example would be: Arguments[2] == Array(2)['float', 'double'] or even: Arguments[2] == Object{0: 'int', 1: 'float', 2: 'double', 'decimal': Array[...]}

But instead I get: Arguments[2] == Object{0: 'template', 1: 'view', 2: 'data', "variable": {...} } which is the object I passed to _eachDeep in the first place...

I guess it has to do with how depth is calculated, that 'float' is in depth 1 under 'childrenPath', and that confuses the code to return the root element... But that's only a speculation after seeing a little the code of _eachDeep.