YuriGor / deepdash

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

filterDeep remove functions when use for omiting #56

Closed GaborTorma closed 3 years ago

GaborTorma commented 4 years ago

filterDeep convert type function (for example: String) to empty object. You can check this pen: https://codepen.io/gabortorma/pen/OJyBWXP You can see on the console. omitByDeep keep the function, filterDeep convert it to empty object.

YuriGor commented 4 years ago

Hi, by default filterDeep uses Lodash cloneDeep internally, and cloneDeep doesn't support functions (because it's impossible to make good assumption in case of functions, how to clone them)

You can provide your own cloning method, check docs here: https://deepdash.io/#filterdeep

So instead of default clone method you can create your own, using, for example, cloneDeepWith from Lodash and handle the case of function values as you would like to.

GaborTorma commented 4 years ago

I don't understand exactly. My omitByDeep solution also use _,cloneDeep and handle the functions as well.

YuriGor commented 4 years ago

Yeah, that's weird, cloneDeep is inconsistent with clone so it returns functions if they are not on the top level. Here is a discussion about this: https://github.com/lodash/lodash/issues/3558

In the case of filterDeep - it doesn't clone the whole source object, so functions inside the object, while being cloned, are not deep, so they returned as empty objects, as expected according to Lodash docs. But in your case functions from the depths of source object remain. Thank you for the catch, I will analyze how this impacts Deepdash.

BTW here is a fork of your codepen with filterDeep example keeping functions: https://codepen.io/yurigor/pen/zYvmzaJ?editors=0010

GaborTorma commented 4 years ago

Thanx for the pen.