This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
omitDeep with function? #62
Comments
Hi, the only way I know to have infinite loop is to have circular references in your data - in this case, you need to enable Here is an example similar to what you need: You can fork this pen, put your data and check if it's working for you. |
Here is a reproducible example: https://stackblitz.com/edit/angular-ivy-b8uhnv?file=src%2Fapp%2Fhello.component.ts I found out that there is a circular references inside self. Can I exclude this key explicitly? |
So if it's a circular ref then no bug here just enable circular check. |
As I see in your example - adding checkCircular:true helps var data = [
{
"id": "dh8ge0",
"name": "Long it takes",
"type": "distance",
"self": this,
"value": 2
},
{
"id": "z765tghj",
"name": "Capability 01",
"type": "checkbox",
"state": "active",
"self": "COMPONENT",
"changed": {
"_isScalar": false,
"observers": [],
"closed": false,
"isStopped": false,
"hasError": false,
"thrownError": null,
"__isAsync": false
}
},
{
"id": "fh390hdas",
"name": "Wildy",
"self": "COMPONENT",
"type": "wildcard"
}
]
console.clear()
console.log(data)
const newData = filterDeep(data, node => node.id !== 'z765tghj', {
checkCircular: true,
childrenPath: ['children'],
onFalse:{skipChildren:true}}
);
console.log(newData); |
Ok, found, we need to checkCircular in filterDeep in case of childrenPath is specified and circular reference is not one of some children because of condensing. |
Just for ur information I got it working by getting rid of the circular dependency which should not be there so thanks for giving me this hint. This is my final solution: const newList: ZoneItem[] =
filterDeep(
this.zones[index].items,
(value: ZoneItem): boolean => {
return value.id !== itemId
},
{
childrenPath: ['children'],
onFalse: { skipChildren: true },
}
) || [] |
Yeah, looks good. If you can avoid circular refs - better to do it, because checking for circular references in filterDeep impacts performance. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Is it possible to use a function in
omitDeep
? I would like to exclude an item and its children from an array but only if the id of an item matches. Please correct me if this isn't the correct function for this but withfilterDeep
I got an infinite loop (idk why).This is what I expect:
PS: Thanks for the great lib. This is a huge time saver for me in my current project.
The text was updated successfully, but these errors were encountered: