deepdash icon indicating copy to clipboard operation
deepdash copied to clipboard

eachDeep with childrenPath == wrong parent, parent path etc

Open AlexanderTheGr8-gr opened this issue 3 years ago • 0 comments

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.

AlexanderTheGr8-gr avatar Mar 24 '23 12:03 AlexanderTheGr8-gr