Pass index to nodeView
I need to know the position of my branch among its siblings. It would be good if Context included a position : Int. Right now I have to build the indexes manually after every change.
I can see how this is can be very helpful, thanks for the suggestion @FranzSkuffka! I have to see what the most sensible solution here could be, among the following options:
- We could make the
context.siblingslist include the node itself at the right position, allowing you to calculate the position through aList.Extra.findIndex. This comes with a slight perf hit but keepsContextsimple. Could run into conflicts with identical nodes, but this is an advanced use case and it seems like an acceptable rough edge. - Expose
position: Intlike you're suggesting. There's no perf hit because this information is in scope at the timenodeViewis called. Major version bump is necessary. - Expose the entire tree traversal path to get to the node. No perf hit for the same reason as in point 2. above. Major version bump here as well.
Do you have thoughts on what is a good design here?
I think
- would change the API so a major version bump would be necessary anyways. It could cause off-by-one errors in those who consume the package. I was expecting the node itself to be included but I'm out of luck.
- Completely would satisfy my use-case. are you sure you can not extend types without a version bump?
- Not sure if it's needed.
I'm for 2 just because it's the simplest version.
In my use case, my parent node holds a list of labels for the children. (It's a 'split' node.) The child node needs to render the label because I want to benefit from the layouting algorithm. In this implementation, the child node would get its label from the list of labels of the parent using its position.
I'm also for 2. because it's a common use-case similar to indexedMap.
You might be right that there is no need for a version bump, I'll take a look. Thanks for all the input!
Thanks for the library :)
@FranzSkuffka sorry for taking so long on this, could not find the time to work this out over the summer. If you still need the feature, I am happy with the position solution, which you can implement as follows:
- the position information you need is the last member of the
pathlist in this function: https://github.com/peterszerzo/elm-arborist/blob/master/src/Arborist.elm#L931. - adding
position: Intto the context object should be the only thing left that you need to compile: https://github.com/peterszerzo/elm-arborist/blob/master/src/Arborist.elm#L1439.
Let me know if you have any other questions.
I have solved the problem on our side already, I probably won't dedicate any time to resolving this anytime soon.
Alright @FranzSkuffka, I'll see if there's anybody else who needs this in the near future and then I'll make a call on adding it.