Open marcelwgn opened 4 years ago
Currently we use a Vector
to store those indices. Since we don't have any operations that would modify the size of an IndexPath, that is how many nesting levels it works with, shouldn't we switch to an array to increase performance?
Are there for sure no situations in which you'd need to modify an IndexPath after it's been created? I feel like there might be some possible use cases for this. 🤔
I am not sure if there are scenarios where one would benefit from it. If the collection changes, e.g. an item suddenly becomes a collection I think it is better to create new IndexPath objects to adress the new items instead of modifying an existing one. SelectionModel just keeps overriding the path objects instead of modifying them.
The big design question at hand I think is whether IndexPath should be mutable or immutable. Should one be able to change the index they are pointing to or should they return/create a new IndexPath if they want to point to something different?
Currently we use a Vector to store those indices. Since we don't have any operations that would modify the size of an IndexPath, that is how many nesting levels it works with, shouldn't we switch to an array to increase performance?
Are there for sure no situations in which you'd need to modify an IndexPath after it's been created? I feel like there might be some possible use cases for this. 🤔
I think it was initially mutable and we changed it to immutable. Array sounds like a good idea to reduce the footprint.
I think it was initially mutable and we changed it to immutable. Array sounds like a good idea to reduce the footprint.
Should I create a tracking issue for that over at WinUI so we update it to array and adjust the API once API review has gone through?
Are there any points that I need to follow up on or I should address here @anawishnoff @MikeHillberg @ranjeshj?
Everything looks good here to me, but I'll leave it to @ranjeshj and @mikeHillberg for any final approval. Thanks Marcel!
I believe we'll need to publish this alongside the SelectionModel spec, which will be in progress for a while until we decide between using a flexible container or attached behaviors to implement this in ItemsRepeater. So, lots of things linked together here :) I'll make sure to keep you updated and in the loop about progress on SelectionModel.
This PR adds the initial API spec for the IndexPath class. @anawishnoff @ranjeshj FYI
Background
To easily track selection in nested collections, we need an object that we can use to uniquely identify an item in nested collections. This can be done with the IndexPath.
Description
The
IndexPath
class provides indexing of nested collections, for example in a TreeView.Examples
In the tree below, using the following IndexPath
would select the item "Kitchen cabinet style", since it is in the second group of first nesting level, first group in the second level of nesting and is the fourth element in the last nesting level.
Creating IndexPath objects
New IndexPaths objects can be created using the static
IndexPath.CreateFrom
andIndexPath.CreateFromIndices
methods:Comparing two IndexPaths
Comparing two
IndexPath
objects can be done using theCompareTo
function:API Notes
API Details
Appendix
Currently we use a
Vector<int>
to store those indices. Since we don't have any operations that would modify the size of an IndexPath, that is how many nesting levels it works with, shouldn't we switch to an array to increase performance?