-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
feat(tree-view): add nodesFlat
prop
#2069
feat(tree-view): add nodesFlat
prop
#2069
Conversation
I don't really see a reason to bloat <TreeView nodes={toHierarchy(nodeList)}> |
@brunnerh Agreed – I like the notion of a separate utility (tree-shakeable) that can be optionally used. |
Shall i make this a separate function? |
@bhavers Yes. Let's make this a separate function. If I'm understanding correctly, I don't think reactivity would be a concern – if
|
Ok, will do so some moment in the upcoming days. Thanks for the extra explanation. |
@metonym I don't get it to work.
And i am also not clear why we would need those definition files. It seems quite double because the javascript files already contain JSDoc type declarations. |
@metonym Never mind, a day later and a fresh quick look reveals that i was looking at the wrong |
@metonym It works. Couple of questions:
|
@bhavers Great work! I've reviewed this and implemented the following changes. I opened #2072 since I was not able to push directly to the outside PR.
type NodeLike = {
id: string | number;
nodes?: NodeLike[];
[key: string]: any;
};
export function toHierarchy<
T extends NodeLike,
K extends keyof Omit<T, "id" | "nodes">,
>(
flatArray: T[] | readonly T[],
/**
* Function that returns the parent ID for a given node.
* @example
* toHierarchy(flatArray, (node) => node.parentId);
*/
getParentId: (node: T) => T[K] | null,
): (T & { nodes?: (T & { nodes?: T[] })[] })[]; |
@metonym Thank you for the explanation. I went through your refactorings and it was really helpful to see how this is done. Although i don't think i fully the grasp the generics wizardry ;-) |
Released in v0.87.0. If using |
No description provided.