Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

filterDeep remove functions when use for omiting #56

Closed
GaborTorma opened this issue May 16, 2020 · 4 comments
Closed

filterDeep remove functions when use for omiting #56

GaborTorma opened this issue May 16, 2020 · 4 comments
Labels
question Further information is requested

Comments

@GaborTorma
Copy link

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
Copy link
Owner

YuriGor commented May 16, 2020

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.

@YuriGor YuriGor closed this as completed May 16, 2020
@YuriGor YuriGor added the question Further information is requested label May 16, 2020
@GaborTorma
Copy link
Author

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

@YuriGor
Copy link
Owner

YuriGor commented May 16, 2020

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:
lodash/lodash#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
Copy link
Author

Thanx for the pen.

@YuriGor YuriGor reopened this Mar 10, 2021
@YuriGor YuriGor closed this as completed Mar 10, 2021
Repository owner locked and limited conversation to collaborators Mar 10, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants