Replies: 7 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. |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
So if it's a circular ref then no bug here just enable circular check. |
Beta Was this translation helpful? Give feedback.
-
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); |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 },
}
) || [] |
Beta Was this translation helpful? Give feedback.
-
Yeah, looks good. If you can avoid circular refs - better to do it, because checking for circular references in filterDeep impacts performance. |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions