[WC-3163] Allow treenode to have self reference association for infinite level of children#2056
[WC-3163] Allow treenode to have self reference association for infinite level of children#2056
Conversation
123cfa3 to
5b56842
Compare
04cd23f to
0c323c4
Compare
0c323c4 to
440a0b9
Compare
|
|
||
| // retrieve new datasource for array of items | ||
| // this is used for checking children's of children (grandchildren) when a branch is expanded | ||
| const filterContents = useCallback( |
There was a problem hiding this comment.
Looks like this can be inlined into filterContent
There was a problem hiding this comment.
Or better be a helper function that gets everything as an argument.
| // ignore "datasource" update triggering fetchChildren again | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
We don't use anything except setFilter, maybe we can keep and check reference to it instead of ignoring whole datasource. This way we are safe if reference ever changes but don't get triggered on any datasource update.
| if (isInfiniteTreeNodesEnabled && fetchingItem.current === undefined) { | ||
| resolvePromise.current = resolve; | ||
| if (Array.isArray(item)) { | ||
| fetchingItem.current = item[0]; | ||
| } else { | ||
| fetchingItem.current = item; | ||
| } | ||
| datasource.setFilter(filterContent(item)); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Is it going to be a never-resolving promise if a fetch is already in progress?
r0b1n
left a comment
There was a problem hiding this comment.
I would try decoupling the fetching/filtering logic from the react part as this if so hard to follow what is happening and makes complexity of react lifecycle add up with lifecycle of data sources.
| ); | ||
|
|
||
| // retrieve new datasource for array of items | ||
| // this is used for checking children's of children (grandchildren) when a branch is expanded |
There was a problem hiding this comment.
Why is so. Aren't we already holding all the previous levels already when we expand one level deeper?
Added parent association property to allow treenode to have infinite levels of children by setting up property to a self reference association.