Closed GaborTorma closed 3 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.
I don't understand exactly. My omitByDeep solution also use _,cloneDeep and handle the functions as well.
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
Thanx for the pen.
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.